Repository navigation
fix(bedrock): resolve aliases in batch file records - #36159
mateo-berri merged 2 commits into
Conversation
|
|
Greptile SummaryThe PR resolves Bedrock batch-record model aliases before provider-specific request transformation and adds deployment-model fallback behavior
Confidence Score: 5/5The PR appears safe to merge No blocking failure remains
|
| Filename | Overview |
|---|---|
| litellm/llms/bedrock/files/transformation.py | Resolves record aliases and deployment fallbacks before selecting Bedrock request transformations |
| tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py | Adds focused regression coverage for chat and embedding aliases, fallback behavior, and upload integration |
Reviews (2): Last reviewed commit: "fix(bedrock): fall back to the batch dep..." | Re-trigger Greptile
| import litellm | ||
|
|
||
| _model: Final = openai_request_body.get("model", "") | ||
| _model = litellm.model_alias_map.get(_model, _model) |
There was a problem hiding this comment.
Alias resolution rebinds locals
Both alias-resolution sites reassign their model variable, violating the repository's immutable-local convention and obscuring the distinction between original and resolved identifiers
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ce5f3cf to
e8c1fe8
Compare
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e8c1fe8. Configure here.
| ) -> tuple[str, BEDROCK_INVOKE_PROVIDERS_LITERAL | None]: | ||
| record_provider: Final = self.get_bedrock_invoke_provider(_strip_llm_routing_prefix(record_model)) | ||
| if record_provider is not None or not target_model: | ||
| return record_model, record_provider |
There was a problem hiding this comment.
Alias fallback skips on provider substrings
Medium Severity
_resolve_batch_record_model_and_provider treats any non-None result from get_bedrock_invoke_provider as proof the record model is a real Bedrock id. That helper also matches provider names as substrings, so an unmapped alias like my-openai-batch or team-meta-proxy gets a false provider hit, skips the target_model fallback, and is left on the passthrough path without the Anthropic (or other) batch schema—reproducing the original anthropic_version validation failures for those alias names.
Reviewed by Cursor Bugbot for commit e8c1fe8. Configure here.
There was a problem hiding this comment.
Substring inference predates this PR, so those alias names fail identically on base. This change only shrinks the failing set; model_alias_map covers the rest.
1a183ef
into
BerriAI:litellm_internal_staging


TLDR
Problem this solves:
How it solves it:
model_alias_mapaliases before picking each record's provider transformUser Flow
Before: the batch reports Completed, but the output holds only
anthropic_version: Field requirederrors and no model repliesbedrock-batch->bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0inmodel_list, plus the batch S3 bucket and job rolepurpose=batch,model=bedrock-batch), each line's body carrying"model": "bedrock-batch", and gets back a long encoded file id{"input_file_id": "<that id>", "endpoint": "/v1/chat/completions", "completion_window": "24h", "model": "bedrock-batch"}and get a batch id with statusvalidating"status": "completed"(~10-15 minutes)anthropic_version: Field required; not one record contains a model replyAfter: the same upload now returns a model reply for every record
bedrock-batch->bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0inmodel_list, plus the batch S3 bucket and job rolepurpose=batch,model=bedrock-batch), each line's body carrying"model": "bedrock-batch", and gets back a long encoded file id{"input_file_id": "<that id>", "endpoint": "/v1/chat/completions", "completion_window": "24h", "model": "bedrock-batch"}and get a batch id with statusvalidating"status": "completed"(~10-15 minutes)modelOutputwith assistant content per record and no validation errorsRelevant issues
Fixes #36156
Linear ticket
Resolves LIT-5304
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito 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
Two live proxies, one per leg, each booted with the same config (
bedrock-batch->bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0, an SSE-KMS-enforced S3 bucket, and a Bedrock batch job role) and fed the same 110-record JSONL whose every line's body says"model": "bedrock-batch". Real Bedrock model-invocation jobs in us-west-2, no mocks. Before leg at merge base f03df1b, after leg at this PR's head e8c1fe8Before (f03df1b, proxy on port 60641): batch says Completed, every record failed
Upload and batch create:
Final batch object after polling (validating -> in_progress -> completed):
Output content through the proxy (HTTP 200, 110 lines), first records verbatim:
{"modelInput":{"messages":[{"role":"user","content":"Reply with the number 7 and nothing else."}],"max_tokens":16},"error":{"errorCode":400,"errorMessage":"anthropic_version: Field required","expired":false,"retryable":false},"recordId":"req-17"} {"modelInput":{"messages":[{"role":"user","content":"Reply with the number 0 and nothing else."}],"max_tokens":16},"error":{"errorCode":400,"errorMessage":"anthropic_version: Field required","expired":false,"retryable":false},"recordId":"req-30"}Counts over all 110 records: 110
anthropic_version: Field requirederrors, 0 other errors, 0 model replies. The rejectedmodelInputlines still carry the raw OpenAI-shaped body, untransformedAfter (e8c1fe8, proxy on port 57789): same flow, every record answered
Same upload and batch create against port 57789 (file
litellm-bedrock-files-bedrock-batch-0ef2cc3f-..., jobarn:aws:bedrock:us-west-2:439158074652:model-invocation-job/bco4nk5uh1hn), polled to"status":"completed"with"error_file_id":nulland emptyfailure_message. Output content through the proxy (HTTP 200), first record verbatim:{"modelInput":{"messages":[{"role":"user","content":[{"type":"text","text":"Reply with the number 6 and nothing else."}]}],"max_tokens":16,"anthropic_version":"bedrock-2023-05-31"},"modelOutput":{"model":"claude-haiku-4-5-20251001","id":"msg_bdrk_01WCAn5P5adweBWVA9KwQiLV","type":"message","role":"assistant","content":[{"type":"text","text":"6"}],"stop_reason":"end_turn","usage":{"input_tokens":18,"output_tokens":5}},"recordId":"req-46"}Counts over all 110 records: 110 assistant
modelOutputreplies, 0 errors of any kind, recordIds exactly req-1..req-110. EachmodelInputshows the proxy rewrote the alias body into Bedrock-native form withanthropic_version: "bedrock-2023-05-31"injected, which is precisely the fix under testSurprises hit during QA:
Type
🐛 Bug Fix
Caveats (if any)
model_alias_mapmodel_alias_mapcovers those tooFinal Attestation