Replies: 4 comments
-
|
Hi @DJWassink! I'm Dosu and I’m helping the zod team. This is by design and is required by the JSON Schema draft-7 spec: you can't have a There isn't a built-in way in Zod to avoid
If you need to support AI models that don't handle If this answers your question, feel free to close the issue! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
So basically GPT doesnt support any draft higher then 7 (draft-2020-12 does indeed support this case). For now we are planning to use factory functions to create new duplicate schemas on the fly if they need modifiers. const aBool = () => z.boolean();
const cachedABool = aBool();
const schema = z.strictObject({
foo: cachedABool,
bar: aBool().describe("somehow this becomes an allOf?"),
}); |
Beta Was this translation helpful? Give feedback.
-
|
this is a known limitation stemming from how JSON Schema draft-7 handles why
|
Beta Was this translation helpful? Give feedback.
-
|
Yes, this is by design in JSON Schema draft-7. In draft-7, {
"description": "somehow this becomes an allOf",
"allOf": [{ "$ref": "#/definitions/__schema0" }]
}This is valid draft-7, but OpenAI's structured output subset doesn't support Fix 1: Use
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am using Zod to generate a json_schema. Sadly the schema got a bit too large and some AI models started outputing gibberish.
To resolve this I tried to enable the
reusedflag with the value"ref". This has been working perfect aside from one little issue.If you have a shared schema (thus one that will be referenced) and apply something extra to this like a
.nullable(). It will create anallOfcondition which results in GPT throwing an error since this condition isn't supported in its json_schema subset.Is this by design since draft-7 can't have properties in the same object as the reference?
And if so, is there an elegant way to make it somehow work?
For the fields that have this issue we for now don't add any modifiers to the properties or inline some schema, but this result in having duplicate definition.
Output which has an
allOfcondition that breaks GPT:{ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": { "foo": { "$ref": "#/definitions/__schema0" }, "bar": { "description": "somehow this becomes an allOf", "allOf": [ { "$ref": "#/definitions/__schema0" } ] } }, "required": [ "foo", "bar" ], "additionalProperties": false, "definitions": { "__schema0": { "type": "boolean" } } }Beta Was this translation helpful? Give feedback.
All reactions