litellm/tests/benchmarks
paveln83 b484c877e1
fix(bedrock): keep shared $defs in Claude tool schemas and bound inlining for other models (#51137)
* fix(bedrock): keep shared $defs in Claude tool schemas and bound inlining for other models

* fix(bedrock): keep unpack_defs memory linear when a schema has many definitions

unpack_defs copied the whole definitions dict for every node it visited, so a
tool schema with N definitions and M nodes held N*M entries at once. Keep the
scope as a tuple of the definitions layers instead, and add a layer only when a
node or a resolved target declares its own $defs or definitions.

* fix(bedrock): inline only legacy refs for Claude and follow root $ref aliases

On Claude the legacy pass now resolves only definitions and components.schemas refs, so a definitions block beside $defs no longer expands the $defs tree. A root $ref is followed through alias chains so the root keeps its object schema. A non-map defs block or a non-string $ref is left as is instead of crashing

* fix(bedrock): walk legacy refs inside a $defs ref and skip malformed definitions on Claude

A $ref the legacy-only pass does not resolve is now walked like any other node, so a
definitions ref inside a $defs entry is inlined instead of dangling. A definitions or
components value that is not an object is dropped instead of failing the request

* fix(bedrock): merge root ref siblings, drop unused $defs, and use the shared inlining budget

A root $ref beside an empty properties block, the shape MCP tools get, now
merges into its target instead of replacing the target's properties, so a
strict Claude tool sends its real arguments again. Claude also stops getting
$defs entries no $ref reaches, which kept unused definitions out of its
input tokens before this branch. Inlining for other models and for legacy
definitions now uses the same 10 MB budget the native Anthropic route uses,
since 1 MB refused an 852 KB expansion that worked at the merge base, and
the 400 now names the bytes of definitions copied

* fix(bedrock): inline every Claude ref outside the root $defs and keep the shared legacy-defs helper as before

Claude on Bedrock only gets the root $defs, so a root $ref into definitions, a $defs block nested in a
property or in a root ref target, and a percent-encoded pointer now resolve before the schema is sent.
Unused-entry pruning counts refs anywhere in the schema, non-Claude models never receive a root $defs,
and unpack_legacy_defs keeps resolving every ref by name for the native Anthropic, Vertex, MCP and
Fireworks routes

* fix(bedrock): keep shadowed and unused Claude defs from changing meaning or spending budget, and inline boolean definitions

* fix(bedrock): resolve a root ref target's own defs as before, fall back on oversized schemas, and accept non-string keys

A Claude tool whose root $ref target declares a $defs name the root also declares with a different body now goes through the merge-base inlining, so refs inside the target keep resolving to the nearer definition

Running past the 10 MB inlining budget now raises ContextWindowExceededError, so context_window_fallbacks fire as they did when Bedrock answered prompt is too long

The tool schema walk accepts dict keys that are not strings, and only the budget overflow maps to the budget error, so an SDK tool with an int property key is no longer rejected with a false 10 MB message

* fix(bedrock): raise a named AttributeError subclass for a $ref target that is not a schema

* fix(bedrock): skip unused root definitions when inlining refs for non-Claude models

Models that get every $ref inlined never receive the root definitions or components blocks, so walking them only spent the shared 10 MB inlining budget and could reject a small tool.

* fix(bedrock): ignore unused legacy definitions when choosing which Claude $defs to keep

A $defs entry reached only from a definitions or components block that the request drops no longer keeps its legacy refs inlined against the shared budget. Legacy entries the body reaches are still followed, so their $defs targets stay.

* fix(bedrock): inline Claude tool refs written without a leading hash

A $ref such as /$defs/Address is not a pointer into the document, so Claude on Bedrock now gets it inlined as at the merge base instead of kept. A root ref like that was dropped by the tool spec and left the tool with no arguments.

* fix(bedrock): inline a Claude root $ref chain the hop limit leaves unresolved

A root $ref chain longer than the hop limit left a root $ref that BedrockToolSpec drops, so Claude got no properties. The resolver now reports such a schema as unresolved, and the tool falls back to bounded full inlining like the base.

* fix(bedrock): keep the Claude $defs reachability pass linear on long ref chains

* test: track the long $defs chain cost with a CodSpeed benchmark instead of wall time

* fix(bedrock): read the Claude $defs capability from the cost map first

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 04:42:19 -08:00
..
__init__.py
conftest.py feat(tokenizer): preserve Python defaults with opt-in Rust dispatch (#42174) 2026-09-22 04:41:11 +00:00
test_a2a_benchmarks.py
test_benchmarks.py refactor: expose core private helpers under public names (#44871) 2026-10-07 00:05:27 +00:00
test_count_tokens_benchmarks.py fix(proxy): count the request's tool_choice on the token count routes (#51133) 2026-11-14 07:53:27 -05:00
test_extraction_guardrail_benchmarks.py feat(extraction): add /v1/extraction with Cloudflare Clairic support (#47473) 2026-10-20 15:51:45 -07:00
test_inference_benchmarks.py
test_json_fragment_accumulator_benchmarks.py test(json_fragment_accumulator): assert peak allocation instead of a drain timing ratio (#43370) 2026-10-28 22:04:47 -07:00
test_mcp_benchmarks.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_prompt_template_benchmarks.py fix(bedrock): keep shared $defs in Claude tool schemas and bound inlining for other models (#51137) 2026-11-24 04:42:19 -08:00
test_realtime_session_merge_benchmarks.py fix(realtime)!: send the Gemini Live setup at the first content so session.update settings apply (#39864) 2026-10-30 01:31:39 -07:00
test_responses_compaction_benchmarks.py fix(responses)!: round-trip Anthropic compaction blocks as compaction items (#46754) 2026-10-21 08:50:19 +00:00
test_sse_lines_benchmarks.py fix(streaming): keep merged think tags balanced and split SSE lines only on CR/LF (#48755) 2026-10-28 17:00:29 -07:00
test_token_counter_pdf_benchmarks.py fix(token_counter): price PDF pages for OpenAI and Azure models the way they bill (#47554) 2026-10-29 18:24:04 -07:00