guidance
guidance copied to clipboard
Should `oneOf` in JSON schemas be supported?
Is your feature request related to a problem? Please describe.
oneOf
in JSON schemas is not currently supported: https://json-schema.org/understanding-json-schema/reference/combining
Describe the solution you'd like Either:
- Explicitly state that
oneOf
is not supported in the documentation, because it is impossible to implement a complex XOR that way during generation (IMO) -- you'd have to be obscenely clever, and it doesn't feel worth it. Leave a note that users can preprocess anyoneOf
s in a schema toanyOf
s if they want a useful approximation. Note: this implies explicitly working toward only ever supporting a subset of the JSON schema. - Allow generation using
oneOf
by treating them likeanyOf
s. Optionally, maybe do some validation on the generated JSON (perhaps with a flag?) and raise an exception if validation fails?
Describe alternatives you've considered There's probably a few different ways to handle this.
Additional context
The mental model is to consider a oneOf
over these two schemas: {"type": "string", "pattern": "\\w{4,10}"}
, {"type": "string", "pattern": "\\w{8,12}"}
. Obviously, an LLM could generate a string with 8 word character that matches both (if it was informed of either). This is a violation. (I would argue that in the real world, such an ill-formed schema is fairly rare, but maybe that's only in my use case.)