Bound the work of `$ref` inlining, decision-model fields, `MessagesBuilder.add` and the `private_key` pattern
Merged
DS
1mo ago+483+483+012345678901234567890123456789-34-34-01234567890123456789
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
Why we make these changes
Four code paths now bound their work:
- Inlining
$defs. Withprefer_inlined_defs,JsonSchemaTransformernow counts the JSON values (objects, arrays and scalars) in each inlined copy of a definition, as written, and raisesUserErroronce the copies pass 250,000 values, before building the rest. Walks withoutprefer_inlined_defsare not limited.
Repro:test_inlining_past_the_value_limit_is_refused_before_the_request, a tool schema of a few dozen values thatmaininlines without a limit. - Decision-model fields.
_fieldsnow counts each definition a field resolves to with the sameInlinedValuescounter type and limit, and stops withUserError, which the decision model already treats as a route it cannot fill.
Repro:test_an_output_type_past_the_value_limit_is_refused, whichmainresolves in full and sends. MessagesBuilder.addrebuilt a message'spartslist on every call, which is quadratic in the parts of one message. It now appends in place to the list it made, and copies a list it did not make once.
Repro:test_messages_builder_extends_its_own_parts_in_place;mainmakes a new list on everyadd.private_keyinDEFAULT_SECRET_PATTERNS. Header lines are now read once each: a line runs to its real line break, or, in a key pasted with escaped newlines, to the last escaped one, and in a key with real line breaks the whole header section up to its blank line is taken together.
Repro:test_a_run_of_backslashes_in_a_header_is_scanned_in_linear_timeandtest_a_run_of_header_lines_is_scanned_in_linear_time, each seconds onmain.
The larger part is core, so this carries pkg:core; the redact_secrets change is in pydantic-ai-harness. #8620 also touches _json_schema.py.
[!WARNING]
Compatibility impact: the private_key entry in DEFAULT_SECRET_PATTERNS has a new value. Code that compares or copies that pattern sees the new one.
Why this can ship in a minor release: the pattern's text is not a documented contract, and the new one redacts the same key material or more on every key shape tested.
Migration: none.
New public surface
None.
Verification
- Limit: 250,000 JSON values per schema. The largest real schema measured, the Anthropic SDK's beta
MessageCreateParams, copies 26,868; its non-betaMessageCreateParams9,715, OpenAI's Responses create params 7,936,list[ModelMessage]3,756 and AG-UI'sRunAgentInput1,563. A schema past the limit raisesUserErrorwhile the request is prepared. - These fail on
mainand pass here:test_inlining_past_the_value_limit_is_refused_before_the_requestandtest_inlining_counts_every_value_of_every_copyintests/test_json_schema.py;test_arguments_past_the_value_limit_are_not_filledandtest_an_output_type_past_the_value_limit_is_refusedintests/models/test_decision.py;test_messages_builder_extends_its_own_parts_in_placeintests/test_ui.py;test_a_run_of_header_lines_is_scanned_in_linear_time,test_a_run_of_backslashes_in_a_header_is_scanned_in_linear_time, and the real-newline cases oftest_a_key_with_a_header_value_broken_across_lines_is_taken_to_its_end_markerintests/harness/guardrails/test_detectors.py. - These pass on both and guard behavior that must not change:
test_a_schema_walked_without_inlining_is_not_limited,test_messages_builder_copies_parts_it_did_not_make,test_an_escaped_encrypted_key_with_no_end_marker_is_still_taken,test_end_marker_text_in_a_header_value_does_not_end_the_key,test_a_backslash_n_in_a_header_of_a_key_with_real_line_breaks_is_text,test_a_key_mixing_real_and_escaped_line_breaks_is_takenandtest_end_marker_text_after_a_key_with_no_end_marker_leaves_the_prose_alone.
What changes for existing users
- A tool or output schema whose inlined
$refs copy more than 250,000 JSON values now raisesUserErrorwhile the request is prepared, on models that inline$defs. - On a decision model, such a route is one it cannot fill. A lone output type like that raises
UserErrorbefore any request is sent. MessagesBuilder.addnow grows thepartslist it made in place, so a reference to that list sees later parts.redact_secrets/secret_datanow redact more of aprivate_keyblock:- A key pasted with escaped newlines, with an escaped blank line before its body, is now redacted even without headers or an
ENDmarker. - A key with real line breaks whose header section holds a line that is not a header is now redacted whole, including any text in that section up to its blank line.
- A block of header lines with no body after them is now redacted, in either line-break style.
- A key pasted with escaped newlines, with an escaped blank line before its body, is now redacted even without headers or an
PR decisions
- 2026-11-03 · The limit counts JSON values, not schema nodes, so it bounds what copied definitions carry (
enum,default,const) too; one counter type and limit serve inlining and decision-model field resolution. (Session: 3a14e78f-adea-4997-a53e-d6c45aab2d7d) - 2026-11-03 · The limit is 250,000 JSON values per schema, not a total across a request's tools. (Session: 3a14e78f-adea-4997-a53e-d6c45aab2d7d)
- 2026-11-03 · Each definition is counted when it is copied, and a cached definition's later copies count what its walk counted, so the walk stops before building past the limit. (Session: bbcb3e70-1ab6-4191-88ed-0dc29c45820b)
- 2026-11-03 · A lone decision-model output type past the limit raises
UserErrorup front rather than after a request. (Session: 3a14e78f-adea-4997-a53e-d6c45aab2d7d) - 2026-11-03 · The
private_keychanges are accepted: across 97 key shapes and 200,000 random blocks it never redacts less key material than before. (Session: 3a14e78f-adea-4997-a53e-d6c45aab2d7d)
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it. The release note is left to the release manager.
- PR title is fit for the release changelog.