fix(anthropic): migrate output_format to output_config.format (GA API) - #21635
fix(anthropic): migrate output_format to output_config.format (GA API)#21635ropoctl wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryMigrates Anthropic structured output from the beta API (
Confidence Score: 5/5Safe to merge — the two-line production change is a straightforward field rename with no side effects, and the updated tests directly verify the new GA shape. The production diff is minimal: one assignment changes which key is written in No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/chat/transformation.py | Two-line change: map_openai_params now writes into output_config.format via setdefault (correctly preserving a pre-existing effort key), and update_headers drops the beta header for GA models while retaining it only for legacy output_format passthrough. |
| tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py | Existing tests updated to assert GA API shape (output_config.format, no beta header); two new tests added covering output_config.format + effort coexistence and end-to-end transform_request output. |
Reviews (7): Last reviewed commit: "fix(anthropic): migrate output_format to..." | Re-trigger Greptile
Additional Comments (1)
|
|
My apologies, the agent that wrote this ran black on the modified files, so there are unrelated whitespace/formatting changes. I will remove those if needed. I verified the change with this script #!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "litellm @ <REDACTED0>",
# "pydantic",
# ]
# ///
"""Test Anthropic structured output with output_config.format (GA API)."""
import os
import litellm
from pydantic import BaseModel
os.environ["ANTHROPIC_API_KEY"] = "<REDACTED1>"
class ExtractedInfo(BaseModel):
name: str
email: str
plan_interest: str
demo_requested: bool
response = litellm.completion(
model="anthropic/claude-sonnet-4-20250514",
api_base="<REDACTED2>",
messages=[
{
"role": "user",
"content": "Extract info: John Smith (john@example.com) wants Enterprise plan, demo next Tuesday 2pm.",
}
],
response_format=ExtractedInfo,
max_tokens=1024,
)
print("=== Response ===")
print(response.choices[0].message.content)
print(f"\n=== Stop reason: {response.choices[0].finish_reason} ===")
# Validate it parses
parsed = ExtractedInfo.model_validate_json(response.choices[0].message.content)
print(f"\n=== Parsed ===")
print(f"Name: {parsed.name}")
print(f"Email: {parsed.email}")
print(f"Plan: {parsed.plan_interest}")
print(f"Demo: {parsed.demo_requested}")
print("\n✅ Anthropic structured output works!") |
|
ptal @greptileai |
Additional Comments (3)
|
|
ptal @greptileai |
Additional Comments (1)
|
pr no longer touches this, ptal @greptileai |
|
@greptileai ptal |
|
@ishaan-jaff would you be able to review this, please? |
|
@ropoctl know why your checks are failing? |
it's flakes coming from files I didn't touch at all |
|
@greptileai ptal |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai ptal — rebased onto the required litellm_oss_staging base. |
Anthropic structured outputs are now GA. The beta `output_format` parameter has moved to `output_config.format`, and beta headers are no longer required. - Updated map_openai_params to set output_config.format instead of output_format - Legacy output_format passthrough still triggers the beta header - Updated and added tests verifying GA API structure and no beta header Ref: https://platform.claude.com/docs/en/build-with-claude/structured-outputs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@greptileai ptal — updated the newer output_config.format regression test for GA no-beta-header behavior; full Anthropic transformation file passes (305 tests). |
|
The CI red is because the targeted branch does not have #32643 yet |
Anthropic's structured output API has graduated from beta:
Changes:
Ref: https://platform.claude.com/docs/en/build-with-claude/structured-outputs
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes