Repository navigation
structured_outputs: support oneOf/anyOf branches and $defs/$ref schemas - #1103
vincenth777 wants to merge 4 commits into
Conversation
- strictify_schema: recurse into list items so object schemas nested inside
oneOf/anyOf/allOf branches get required + additionalProperties: false.
- coerce_xml_types: resolve $ref pointers against the top-level schema's
$defs via a new root_schema parameter (defaults to None for backward compat).
Signed-off-by: Vince Huang <vincehuang@mercor.com>
- strictify_schema: skip allOf branches (conjunctive merge would reject fields contributed by sibling branches) - coerce_xml_types: support nullable union types like ["integer","null"] (parity with CSV path); make root_schema required; use removeprefix - add tests: anyOf strictification, allOf composition regression guard, nullable XML coercion; extend oneOf test with second-branch case - add data/example_complex_schema.jsonl (5 toy rows) and an end-to-end smoke test that round-trips every row with hand-crafted gold outputs Signed-off-by: Vince Huang <vincehuang@mercor.com>
|
Nullable XML coercion: Toy examples: added Other small cleanups inside the new code:
Verified empirically: swapped |
|
/ok to test 9bd5897 |
|
/review |
Two fixes to
resources_servers/structured_outputs/app.pyso the verifier handles complex JSON Schema features that it currently mishandles:strictify_schema: recurse into list items so object schemas nested insideoneOf/anyOf/allOfbranches getrequiredandadditionalProperties: falseapplied. Without this, extra or missing fields inside a composite branch are not caught by validation.coerce_xml_types: resolve$refpointers against the top-level schema's$defsbefore coercion, via a newroot_schemaparameter. Without this,$ref-based fields with non-string types (integer, number, boolean) are not coerced and fail validation.Both changes are backward compatible:
strictify_schemastill handles plain dict schemas identically, andcoerce_xml_typesgains aroot_schema=Nonedefault so existing call sites are unaffected.Test plan
test_verify_json_with_oneof_strictifies_branches: valid branch passes; extra/missing field inside aoneOfbranch rejectedtest_verify_xml_with_defs_refs: integer under$refcoerces correctly; non-numeric content rejectedtest_app.pytests still pass (JSON, YAML, XML, TOML, CSV)Context
Surfaced while building structured-output tasks with complex schemas, context discussed with JK