What
schema_type_to_python handles type, enum, const, and JSON Schema type arrays, but not anyOf or oneOf. A property expressed with either union keyword therefore falls through to Any.
That loses constraints when json_schema_dict_to_pydantic feeds the converted type back into structured generation.
Reproduction
from outlines.types.json_schema_utils import schema_type_to_python
print(schema_type_to_python({
"anyOf": [{"type": "integer"}, {"type": "string"}],
}, "pydantic"))
# typing.Any (expected Union[int, str])
print(schema_type_to_python({
"oneOf": [{"type": "boolean"}, {"type": "null"}],
}, "pydantic"))
# typing.Any (expected Optional[bool])
The resulting Pydantic schema has no value constraint at all:
M = json_schema_dict_to_pydantic({
"type": "object",
"properties": {
"value": {"anyOf": [{"type": "integer"}, {"type": "string"}]},
},
"required": ["value"],
})
print(M.model_json_schema()["properties"]["value"])
# {"title": "Value"}
Expected
Map each branch recursively and combine them with Union, just as the existing JSON Schema type-array path does. For Python typing/Pydantic, oneOf cannot preserve exclusivity for overlapping branches, but retaining the union of allowed value types is still strictly better than widening to Any.
What
schema_type_to_pythonhandlestype,enum,const, and JSON Schema type arrays, but notanyOforoneOf. A property expressed with either union keyword therefore falls through toAny.That loses constraints when
json_schema_dict_to_pydanticfeeds the converted type back into structured generation.Reproduction
The resulting Pydantic schema has no value constraint at all:
Expected
Map each branch recursively and combine them with
Union, just as the existing JSON Schema type-array path does. For Python typing/Pydantic,oneOfcannot preserve exclusivity for overlapping branches, but retaining the union of allowed value types is still strictly better than widening toAny.