Skip to content

fix(anthropic): preserve optional Responses tool properties - #34784

Open
eugene-yao-zocdoc wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
eugene-yao-zocdoc:fix/anthropic-responses-optional-tool-schema
Open

fix(anthropic): preserve optional Responses tool properties#34784
eugene-yao-zocdoc wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
eugene-yao-zocdoc:fix/anthropic-responses-optional-tool-schema

Conversation

@eugene-yao-zocdoc

@eugene-yao-zocdoc eugene-yao-zocdoc commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

A live OpenAI Responses API probe using a synthetic search-tool schema reproduced the provider behavior behind this bug:

  • When strict was omitted, Responses normalized the tool to strict: true, changed required from ["query"] to ["query", "cursor", "context_channel_id"], and generated empty strings for the optional fields.
  • With strict: false, Responses preserved required: ["query"] and generated only {"query":"zz_responses_probe"}.

The patched adapter now emits strict: false for ordinary Anthropic tools while preserving an explicit top-level Anthropic strict: true request. The sibling Chat Completions adapter also keeps an explicit strict value at function level rather than placing it inside the JSON Schema.

After rebasing onto litellm_internal_staging, focused verification against commit 6dbd305f passed:

........................................................................ [ 40%]
........................................................................ [ 80%]
...................................                                      [100%]
179 passed, 1 warning in 3.84s

The edited modules pass py_compile, and git diff --check reports no errors.

Type

🐛 Bug Fix

Changes

  • Explicitly disable the OpenAI Responses API's strict-by-default normalization when translating ordinary Anthropic tools.
  • Preserve explicitly requested Anthropic strict tool validation across both Responses and Chat Completions routes.
  • Add the top-level strict field to the Anthropic tool type.
  • Add regressions proving optional properties stay optional, explicit strict validation remains enabled, and strict does not leak into the parameters schema.

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@eugene-yao-zocdoc

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR preserves Anthropic tool strictness across OpenAI-compatible adapters

  • Adds an optional top-level strict field to the Anthropic tool type
  • Maps explicit strict validation to Chat Completions function tools
  • Disables Responses API strict-by-default behavior for ordinary tools while preserving explicit strict: true
  • Adds regression coverage for optional properties and strict-field placement

Confidence Score: 5/5

The PR appears safe to merge

No blocking failure remains

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Moves an explicit Anthropic strict setting to the OpenAI function-tool level without leaking it into the parameters schema
litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py Emits explicit Responses function-tool strictness, defaulting ordinary Anthropic tools to non-strict handling
litellm/types/llms/anthropic.py Extends the Anthropic custom-tool TypedDict with the optional top-level strict field
tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py Verifies explicit strict validation remains at the Chat Completions function level
tests/test_litellm/llms/anthropic/experimental_pass_through/responses_adapters/test_responses_adapters_transformation.py Verifies optional properties remain optional and explicit Responses strict validation is preserved

Reviews (2): Last reviewed commit: "fix(anthropic): preserve optional Respon..." | Re-trigger Greptile

@eugene-yao-zocdoc
eugene-yao-zocdoc marked this pull request as ready for review July 27, 2026 14:22
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@eugene-yao-zocdoc
eugene-yao-zocdoc changed the base branch from litellm_oss_daily_2026_07_20 to litellm_internal_staging July 27, 2026 20:01
Generated with AI

Co-Authored-By: Claude Code
@eugene-yao-zocdoc
eugene-yao-zocdoc force-pushed the fix/anthropic-responses-optional-tool-schema branch from 64906dd to 6dbd305 Compare July 27, 2026 20:05
@codspeed-hq

codspeed-hq Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing eugene-yao-zocdoc:fix/anthropic-responses-optional-tool-schema (6dbd305) with litellm_internal_staging (bb6bb66)

Open in CodSpeed

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.

1 participant