UN-3709 [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models#2165
UN-3709 [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models#2165jaseemjaskp wants to merge 1 commit into
Conversation
…odels Configuring Claude Sonnet 5 via Azure AI Foundry (azure_ai adapter) failed the connection test with "temperature is deprecated for this model". Anthropic removed the sampling params (temperature/top_p/top_k) starting with Opus 4.7, and every model since (Opus 4.8, Sonnet 5, Fable 5, Mythos 5) rejects them too. The SDK1 sampling-param strip only recognized claude-opus-4-7, so for Sonnet 5 the strip never fired and Pydantic's default temperature=0.1 was forwarded to Azure -> Anthropic -> 400. Replace the single detection pattern with a maintained stem list covering all sampling-deprecated Claude models, keeping the trailing-edge boundary that rejects prefix collisions (claude-sonnet-50) and alpha continuations (...-5verbose). Extend tests with positives, boundary negatives, and adapter wiring for Sonnet 5 (including the reported azure_ai_foundry case).
WalkthroughThe Claude sampling-parameter detection now uses an allowlist of model stems covering Opus 4.7 and later releases. Tests add positive, collision-negative, and adapter validation coverage for Sonnet 5 and other supported models. ChangesClaude sampling detection
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 | Extends the existing model allowlist without changing normalization, stripping behavior, or adapter integration. |
| unstract/sdk1/tests/test_sampling_strip.py | Adds coverage for new model families, provider identifier formats, boundary collisions, and adapter validation. |
Reviews (1): Last reviewed commit: "[FIX] Strip deprecated temperature for C..." | Re-trigger Greptile
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
unstract/sdk1/tests/test_sampling_strip.py (1)
330-358: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider adding a Bedrock cross-region profile positive case.
The
POST_47_POSITIVESlist covers Bedrock foundation model ids (anthropic.claude-sonnet-5-...) but not cross-region profile variants (us.anthropic.claude-sonnet-5-...,eu.,apac.,global.) that are explicitly documented inbase1.pylines 34-35. The regex would match these (leading text passes through,-delimiter after stem), but an explicit test case would guard against future anchor changes.➕ Suggested addition
"anthropic.claude-sonnet-5-20260101-v1:0", # Bedrock foundation model id + "us.anthropic.claude-sonnet-5-20260101-v1:0", # Bedrock cross-region profile + "global.anthropic.claude-sonnet-5-20260101-v1:0", # Bedrock global profile "vertex_ai/claude-sonnet-5@20260101", # Vertex AI🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@unstract/sdk1/tests/test_sampling_strip.py` around lines 330 - 358, Add a positive Bedrock cross-region profile test case to the existing Sonnet 5 validation coverage, using representative us., eu., apac., or global. model IDs alongside the foundation ID in the relevant POST_47_POSITIVES data. Ensure the case exercises the Bedrock validator and confirms all _DEPRECATED_SAMPLING_PARAMS are stripped, preserving coverage through the existing parameterized test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@unstract/sdk1/tests/test_sampling_strip.py`:
- Around line 330-358: Add a positive Bedrock cross-region profile test case to
the existing Sonnet 5 validation coverage, using representative us., eu., apac.,
or global. model IDs alongside the foundation ID in the relevant
POST_47_POSITIVES data. Ensure the case exercises the Bedrock validator and
confirms all _DEPRECATED_SAMPLING_PARAMS are stripped, preserving coverage
through the existing parameterized test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2f93c006-7ce3-4afb-b7ca-e0b6b6307334
📒 Files selected for processing (2)
unstract/sdk1/src/unstract/sdk1/adapters/base1.pyunstract/sdk1/tests/test_sampling_strip.py
Unstract test resultsPer-group results
Critical paths
|



What
Extend the SDK1 sampling-parameter strip so it also fires for Claude Sonnet 5 and the other Claude models that deprecated
temperature/top_p/top_k(Opus 4.8, Fable 5, Mythos 5), not just Opus 4.7.Why
Configuring Claude Sonnet 5 via Azure AI Foundry (
azure_aiadapter) failed the connection test with:Anthropic removed the sampling params (
temperature/top_p/top_k) starting with Claude Opus 4.7, and every model released since — Opus 4.8, Sonnet 5, Fable 5, Mythos 5 — rejects them with a 400 (directly and through the Bedrock / Azure AI Foundry / Vertex proxies). Opus 4.6 / Sonnet 4.6 and older still accept them.SDK1 already strips these params via
_strip_deprecated_sampling_params()(wired into every adapter'svalidate()), but the detection allowlist only matchedclaude-opus-4-7. So for Sonnet 5 the strip never fired, and becauseBaseChatCompletionParameters.temperaturedefaults to0.1, Pydantic'smodel_dump()re-emittedtemperature=0.1, which litellm forwarded to Azure → Anthropic → the 400.How
unstract/sdk1/src/unstract/sdk1/adapters/base1.py:_SAMPLING_DEPRECATED_MODEL_PATTERNStuple with a maintained_SAMPLING_DEPRECATED_MODEL_STEMSlist (claude-opus-4-7,claude-opus-4-8,claude-sonnet-5,claude-fable-5,claude-mythos-5), each compiled with the existing trailing-edge boundary(?=$|[-:@/]|v\d)that rejects prefix collisions (claude-sonnet-50) and alpha continuations (...-5verbose).The strip wiring, the per-adapter integration (including
AzureAIFoundryLLMParameters.validate), and theazure_aipath are unchanged — only the detection list grows.unstract/sdk1/tests/test_sampling_strip.py: add positives for the newly-covered models (native, Azure-prefixed, deployment-name, case, separator, version-tag, Bedrock, Vertex forms), boundary negatives (claude-sonnet-50,claude-sonnet-4-5/4-6), and adapter-wiring tests including the exact reported scenario.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. The change only adds model stems to a narrow detection allowlist; models that already accept sampling params (Opus 4.6/4.5, Sonnet 4.5/4.6, Haiku, non-Anthropic providers) are unaffected — verified by existing and newly-added negative tests. The trailing-edge boundary is preserved, so no new false positives (
claude-sonnet-50,claude-sonnet-4-5) are introduced.Database Migrations
Env Config
Relevant Docs
Related Issues or PRs
Dependencies Versions
Notes on Testing
pytest tests/test_sampling_strip.py— 87 passed (pre-commit selected-tests hook also green).AzureAIFoundryLLMParameters.validate({"model": "claude-sonnet-5", "temperature": 0.1, ...})returnsmodel == "azure_ai/claude-sonnet-5"withtemperatureabsent.model/deployment string. Azure AI Foundry deployments with an opaque name (e.g.sonnet5-prod) must be named to includeclaude-sonnet-5for the strip to fire.Screenshots
Checklist
I have read and understood the Contribution Guidelines.