structuredValidator
@forge/monorepo / backend/src / structuredValidator
Function: structuredValidator()
structuredValidator(
schema): (value) => {ok:true; } | {detail:string;ok:false; }
Defined in: backend/src/models/streaming.ts:252
A schema this process can actually check, or a refusal — task #243.
The rule: only a schema with a validator is accepted for structured output. Zod (a direct dependency) and anything else implementing Standard Schema qualify. A bare JSON-schema object does not, and refusing it is a deliberate choice rather than an omission:
- The AI SDK's
jsonSchema()wrapper returns{ _type, jsonSchema, validate }withvalidateundefined. It constrains the provider's generation and validates nothing coming back. Accepting one would mean the platform says "structured", the provider mostly complies, and nobody checks — which is a softer version of the bug being fixed, not a fix. - Validating JSON schema properly needs
ajv, and that is a new runtime dependency for every consumer of a package whose entire dependency list isaiandzod. Not worth it whenz.object({...})is one line and already validates.
So this fails closed, at wiring time, with a message naming the fix. Tools keep taking JSON schema — a tool's arguments are validated by the provider and a bad call is a tool error the model can see and retry, which is a different situation from a guarantee made to a caller about a return value.
Parameters
schema
unknown
Returns
(value) => { ok: true; } | { detail: string; ok: false; }