You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(schema): decode URI fragments before JSON Pointer traversal #5254
Baseline: 3590e5d949638b86fb402cdde42460e6ccbc4933 in openai/openai-agents-python.
resolve_ref() splits the URI fragment and applies ~1/~0 escapes without first decoding percent-encoded UTF-8. A valid reference can raise KeyError, or silently resolve to a different existing schema when encoded and literal-percent names coexist.
With $defs["A B"]={"type":"string"} and $defs["A%20B"]={"type":"integer"}, #/$defs/A%20B resolves to integer before the patch and to string after it.
Expected behavior
Decode the local URI fragment once with urllib.parse.unquote(..., errors="strict"), then split its JSON Pointer path and retain the existing ~1-before-~0 order and nested-resource guard. Do not use unquote_plus. Add regression tests for Unicode, percent signs, structural separators, plus signs and name collisions.
Evidence and proposed scope
24 focused checks; 14 fail before the patch. The collision case proves wrong-target selection, not merely an exception.
Focused execution uses the exact resolve_ref and _declares_schema_resource bodies with explicit is_dict/UserError imports supplied at the boundary. It does not exercise the complete strict-schema conversion pipeline, an installed Agents SDK or an OpenAI API request. This does not add array-index or root-# support and does not claim complete RFC 6901 implementation.
A narrowly scoped patch and regression tests are prepared. No model-quality, full-project CI, or GPU throughput claim is made.
Reporting through an issue in accordance with the current collaborator-only PR policy. The affected source blob remains unchanged at current main c513dd181441baffa841151d84cf8bbac38556cf.
I reproduced both failure modes on main and prepared a fix — since this repo only accepts PRs from within the organization, I'm leaving the patch here for maintainers to pick up (happy to adapt if you'd rather I don't).
Root cause: resolve_ref() (src/agents/strict_schema.py) splits the $ref fragment and applies ~1/~0 escapes without first decoding percent-encoded octets. #/$defs/a%20b raises KeyError when only a b is defined, and with both A B and A%20B defined it silently resolves to the literal A%20B entry.
Fix (src/agents/strict_schema.py):
path=unquote(ref[2:], errors="strict").split("/")
Decode the fragment once with urllib.parse.unquote (not unquote_plus — + is not a space in URI fragments), keeping errors="strict" so malformed UTF-8 (%FF) fails loudly, then keep the existing ~1-before-~0 pointer handling and nested-resource guard unchanged.
Activity
KaiyiQuan commentedon Sep 30, 2026
I reproduced both failure modes on main and prepared a fix — since this repo only accepts PRs from within the organization, I'm leaving the patch here for maintainers to pick up (happy to adapt if you'd rather I don't).
Root cause:
resolve_ref()(src/agents/strict_schema.py) splits the $ref fragment and applies~1/~0escapes without first decoding percent-encoded octets.#/$defs/a%20braisesKeyErrorwhen onlya bis defined, and with bothA BandA%20Bdefined it silently resolves to the literalA%20Bentry.Fix (
src/agents/strict_schema.py):Decode the fragment once with
urllib.parse.unquote(notunquote_plus—+is not a space in URI fragments), keepingerrors="strict"so malformed UTF-8 (%FF) fails loudly, then keep the existing~1-before-~0pointer handling and nested-resource guard unchanged.Tests added (
tests/test_strict_schema.py): Unicode keys (caf%C3%A9→café), percent signs (%25→ literal%),~1separators, literal+, name collisions, malformed UTF-8 raises. Full file: 71 passed, ruff clean.