Skip to content

fix: preserve multi-branch union schemas - #271

Open
Oaklight wants to merge 5 commits into
masterfrom
worktree-fix-union-schema
Open

Oaklight wants to merge 5 commits into
masterfrom
worktree-fix-union-schema

Conversation

@Oaklight

Copy link
Copy Markdown
Owner

Summary

  • Preserve heterogeneous anyOf/oneOf branches (e.g., float | list[float] | None) instead of collapsing to the first non-null branch
  • Normalize bare tuple annotations to tuple[Any, ...] so they render as {type: "array"} instead of {}
  • Fix _resolve_enum() to handle PEP 604 X | Y unions (types.UnionType)
  • Vendor zerodep jsonschema 0.4.1 with the upstream union-preservation fix

Cherry-picks @rajeeva's initial fix from #270, then layers upstream corrections on top. The core schema flattening fix lives in zerodep (Oaklight/zerodep#173) and llm-rosetta (Oaklight/llm-rosetta#747); this PR vendors the zerodep fix and adds toolregistry-specific improvements (bare tuple normalization, PEP 604 enum resolution).

Fixes #269.
Supersedes #270.

Test plan

  • pytest tests/test_schema_sanitization.py — 25 passed, 1 xfail (xfail depends on llm-rosetta#747)
  • pytest tests/test_parameter_models.py — 48 passed
  • Full suite (excluding MCP integration) — 256 passed, 1 pre-existing MCP failure
  • Rajeev's reproduction cases produce correct anyOf output

rajeeja and others added 4 commits September 23, 2026 18:52
…hemas

The upstream zerodep fix (jsonschema 0.4.1) makes the
resolve_refs → merge_allof → sanitize bypass unnecessary —
flatten_schema now preserves multi-branch unions natively.

Restore _simplify_nullable_schemas to its original non-recursive
form since the upstream pipeline handles nested schemas.
Preserves multi-branch anyOf/oneOf unions instead of collapsing
to the first non-null branch.

Upstream: Oaklight/zerodep#173
Cover str|int, single nullable collapse, and get_schema() pipeline
for multi-branch unions across openai-chat and anthropic formats.
- Add --extra-index-url for TestPyPI so CI can resolve dev releases
- Bump llm-rosetta dependency to pick up the union-preservation fix
  (Oaklight/llm-rosetta#747)
- Remove xfail marker from test_get_schema_preserves_multi_union

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve scalar and sequence branches in generated union schemas

2 participants