[FIX] Strip deprecated sampling params for Claude Opus 4.7 onwards#2103
[FIX] Strip deprecated sampling params for Claude Opus 4.7 onwards#2103pk-zipstack wants to merge 2 commits into
Conversation
Extend the Anthropic sampling-param deprecation detector beyond Opus 4.7 to cover every Opus release from 4.7 onwards: 4.7, 4.8, 4.9 and Opus 5+. The previous single pattern matched only `claude-opus-4-7`, so callers on `claude-opus-4-8` (and future Opus ids) still sent `temperature` / `top_p` / `top_k` and 400'd with "temperature is deprecated for this model". Replace the lone pattern with two anchored ones — `claude-opus-4-[789]` and `claude-opus-[5-9]` — keeping the existing trailing-edge boundary so prefix collisions (`claude-opus-4-70`, `claude-opus-4-7verbose`) and the sampling-supporting `claude-opus-4-1..4-6` still do not match. Extend test_sampling_strip.py with 4.8/4.9/Opus 5+ positives and Opus 5 boundary negatives. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughThe ChangesOpus 4.7+ Sampling Deprecation Detection
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| unstract/sdk1/src/unstract/sdk1/adapters/base1.py | Widens the sampling-param deprecation detector from a single claude-opus-4-7 literal to two anchored patterns covering Opus 4.7–4.9 and Opus 5+; logic, adapter wiring, and strip contract are unchanged. |
| unstract/sdk1/tests/test_sampling_strip.py | Extends detection unit tests with 4.8/4.9/Opus-5+ positives and boundary negatives; adapter-wiring helpers still hardcode 4.7 model IDs rather than exercising the new patterns end-to-end. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Adapter .validate called] --> B[_strip_deprecated_sampling_params]
B --> C{model or model_id\nfield present?}
C -- No --> G[Return unchanged dict]
C -- Yes --> D[Normalize: lowercase\n. and _ to -]
D --> E{Any pattern matches?}
E -- Pattern 1: claude-opus-4-7/8/9 --> F[Strip temperature, top_p, top_k]
E -- Pattern 2: claude-opus-5 thru 9 --> F
E -- No match --> H{Opaque Bedrock AIP ARN?}
H -- Yes --> I[Log debug breadcrumb\nReturn unchanged dict]
H -- No --> G
F --> J[Return copy without sampling params]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[Adapter .validate called] --> B[_strip_deprecated_sampling_params]
B --> C{model or model_id\nfield present?}
C -- No --> G[Return unchanged dict]
C -- Yes --> D[Normalize: lowercase\n. and _ to -]
D --> E{Any pattern matches?}
E -- Pattern 1: claude-opus-4-7/8/9 --> F[Strip temperature, top_p, top_k]
E -- Pattern 2: claude-opus-5 thru 9 --> F
E -- No match --> H{Opaque Bedrock AIP ARN?}
H -- Yes --> I[Log debug breadcrumb\nReturn unchanged dict]
H -- No --> G
F --> J[Return copy without sampling params]
Reviews (2): Last reviewed commit: "[FIX] Generalize Azure deployment-name d..." | Re-trigger Greptile
…pus id Address review feedback: the _has_deprecated_sampling_params docstring cited `claude-opus-4-7` as the Azure AI Foundry deployment-name example, which is stale now that the strip covers Opus 4.7 onwards. Reference the relevant model id generally (e.g. claude-opus-4-8). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Unstract test resultsPer-group results
Critical paths
|



What
unstract/sdk1/.../adapters/base1.pyto cover every Opus release from 4.7 onwards — Opus 4.7, 4.8, 4.9 and Opus 5+ — instead of onlyclaude-opus-4-7.test_sampling_strip.pywith 4.8 / 4.9 / Opus 5+ positives and Opus 5 boundary negatives.Why
PR #1934 added the strip but keyed it to a single literal —
claude-opus-4-7. Anthropic has since shipped Opus 4.8, which deprecates the same sampling parameters (temperature,top_p,top_k). Becauseclaude-opus-4-8does not match the old pattern, those calls reach the provider withtemperaturestill set and 400:litellm cannot fix this for us — upstream
get_supported_openai_params()still reportstemperatureas supported for these models (open bug BerriAI/litellm#26444, unshipped), sodrop_params=Trueis a no-op. The strip inbase1.pyremains the only thing preventing the 400, and it must track each new Opus id.Reference: https://platform.claude.com/docs/en/about-claude/models/whats-new-claude-4-7
How
base1.py:claude-opus-4-7pattern becomes two patterns coveringclaude-opus-4-[789]andclaude-opus-[5-9]. The existing trailing-edge lookahead ($, a-/:/@//delimiter, orv<digit>) is preserved, so:claude-opus-4-8), Bedrock foundation models / cross-region profiles / ARNs (us.anthropic.claude-opus-4-8-<date>-v1:0), Vertex (vertex_ai/claude-opus-4-8@<date>), Azure deployments embedding the id, and dot/underscore variants.claude-opus-4-70,claude-opus-4-7verbose), the sampling-supportingclaude-opus-4-1..4-6, and Opus 5 boundary cases (claude-opus-50,claude-opus-5verbose)._strip_deprecated_sampling_params, themodel/model_idAIP fallback, or the four adapter call sites — only the detection table widened.test_sampling_strip.py:anthropic/, Bedrock id + ARN, cross-region, Vertex, Azure, dotted), 4.9, and Opus 5/6.claude-opus-50,claude-opus-5verbose,claude-opus-4-1,anthropic.claude-opus-4-1-....Known limitation
claude-opus-4-[789]covers 4.7–4.9 but not a hypotheticalclaude-opus-4-10. Anthropic's cadence (4-5 → 4-6 → 4-7 → 4-8) makes an Opus 5 jump far more likely than a 4-10, and Opus 5+ is already covered. Fable 5 / Mythos 5 (claude-fable-5,claude-mythos-5) also forbid these params but are out of scope here (this change is Opus-only, per the "4.7 onwards" scope); they would each need a pattern if routed through this SDK.Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)
No.
temperature/top_p/top_kare unaffected — verified by negative tests forclaude-opus-4-1..4-6,claude-sonnet-4-7,claude-haiku-4-5,claude-3-5-sonnet, and non-Anthropic providers (gpt-4o,gemini-2.0-flash), which all keep their sampling params.claude-opus-4-70,claude-opus-4-7verbose) still hold._strip_deprecated_sampling_paramscontract, AIPmodel_idfallback, and adapter wiring are untouched.🤖 Generated with Claude Code