Skip to content

UN-3709 [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models#2165

Open
jaseemjaskp wants to merge 1 commit into
mainfrom
fix/sonnet-5-temperature-strip
Open

UN-3709 [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models#2165
jaseemjaskp wants to merge 1 commit into
mainfrom
fix/sonnet-5-temperature-strip

Conversation

@jaseemjaskp

@jaseemjaskp jaseemjaskp commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

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_ai adapter) failed the connection test with:

Error from LLM adapter 'azure_ai': Azure_aiException -
{"type":"error","error":{"type":"invalid_request_error",
 "message":"temperature is deprecated for this model."}}

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's validate()), but the detection allowlist only matched claude-opus-4-7. So for Sonnet 5 the strip never fired, and because BaseChatCompletionParameters.temperature defaults to 0.1, Pydantic's model_dump() re-emitted temperature=0.1, which litellm forwarded to Azure → Anthropic → the 400.

How

unstract/sdk1/src/unstract/sdk1/adapters/base1.py:

  • Replace the single-pattern _SAMPLING_DEPRECATED_MODEL_PATTERNS tuple with a maintained _SAMPLING_DEPRECATED_MODEL_STEMS list (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).
  • Update the surrounding comments/docstrings to reflect the broader model set.

The strip wiring, the per-adapter integration (including AzureAIFoundryLLMParameters.validate), and the azure_ai path 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

  • None

Env Config

  • None

Relevant Docs

Related Issues or PRs

Dependencies Versions

  • No dependency changes

Notes on Testing

  • pytest tests/test_sampling_strip.py — 87 passed (pre-commit selected-tests hook also green).
  • End-to-end check: AzureAIFoundryLLMParameters.validate({"model": "claude-sonnet-5", "temperature": 0.1, ...}) returns model == "azure_ai/claude-sonnet-5" with temperature absent.
  • Caveat (existing, documented limitation): detection needs the model id to appear in the model/deployment string. Azure AI Foundry deployments with an opaque name (e.g. sonnet5-prod) must be named to include claude-sonnet-5 for the strip to fire.

Screenshots

Checklist

I have read and understood the Contribution Guidelines.

…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).
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The 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.

Changes

Claude sampling detection

Layer / File(s) Summary
Expand Claude model detection
unstract/sdk1/src/unstract/sdk1/adapters/base1.py
Generates anchored deprecated-sampling patterns for multiple Claude model stems and updates the related comments and documentation.
Validate model coverage
unstract/sdk1/tests/test_sampling_strip.py
Adds post-Opus 4.7 positives, Sonnet 5 prefix-collision negatives, and adapter validation tests covering multiple backends and Vertex AI.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly names the main change: stripping deprecated sampling params for Claude Sonnet 5 and post-4.7 models.
Description check ✅ Passed The description follows the template closely and includes the required sections with concrete details, testing, risks, and related issues.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sonnet-5-temperature-strip

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends Claude sampling-parameter stripping to models released after Opus 4.7. The main changes are:

  • Adds allowlisted stems for Opus 4.8, Sonnet 5, Fable 5, and Mythos 5.
  • Generates escaped detection patterns while preserving the existing trailing boundary.
  • Adds provider-specific, normalization, collision, and adapter-wiring tests.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

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

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
unstract/sdk1/tests/test_sampling_strip.py (1)

330-358: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider adding a Bedrock cross-region profile positive case.

The POST_47_POSITIVES list 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 in base1.py lines 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

📥 Commits

Reviewing files that changed from the base of the PR and between 09b6834 and c91e8f0.

📒 Files selected for processing (2)
  • unstract/sdk1/src/unstract/sdk1/adapters/base1.py
  • unstract/sdk1/tests/test_sampling_strip.py

@github-actions

Copy link
Copy Markdown
Contributor

Unstract test results

Per-group results

Status Group Tier Passed Failed Errors Skipped Duration (s)
e2e-login e2e 2 0 0 0 1.8
e2e-smoke e2e 2 0 0 0 1.2
integration-backend integration 56 0 0 27 47.4
integration-connectors integration 1 0 0 7 8.3
unit-backend unit 118 0 0 0 22.0
unit-connectors unit 63 0 0 0 10.3
unit-core unit 27 0 0 0 1.4
unit-platform-service unit 15 0 0 0 2.8
unit-rig unit 69 0 0 0 3.9
unit-sdk1 unit 410 0 0 0 25.5
unit-workers unit 0 0 0 0 29.2
TOTAL 763 0 0 34 153.7

Critical paths

⚠️ Critical paths not yet covered

  • workflow-create-execute — Create a workflow, configure source+destination, execute, poll, fetch result. (entry: POST /api/v1/workflow/{id}/execute/; declared coverage: e2e-workflow)
  • api-deployment-run — Deploy a workflow as an API, POST a document, receive structured JSON. (entry: POST /deployment/api/{org}/{name}/; declared coverage: e2e-api-deployment)
  • prompt-studio-fetch-response — Prompt Studio: create project, add prompt, run single-pass, get response. (entry: POST /api/v1/prompt-studio/prompt-studio-tool/{id}/fetch_response/; declared coverage: e2e-prompt-studio)
  • pipeline-etl-execute — Run an ETL pipeline from source connector to destination. (entry: POST /api/v1/pipeline/{id}/execute/; declared coverage: no groups declared)
  • usage-token-tracking — Per-execution token usage is recorded and retrievable. (entry: GET /api/v1/usage/get_token_usage/; declared coverage: no groups declared)
  • workflow-execution-fan-out — Multi-file workflow execution fans out to file-processing workers and rejoins. (entry: internal: backend → rabbitmq → workers/file_processing; declared coverage: no groups declared)
  • callback-result-delivery — Async results are posted back via the callback worker. (entry: internal: workers/callback → backend /internal endpoints; declared coverage: no groups declared)
✅ Covered critical paths
  • auth-login — covered by e2e-login
  • adapter-register-llm — covered by integration-backend

@jaseemjaskp jaseemjaskp changed the title [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models UN-3709 [FIX] Strip deprecated temperature for Claude Sonnet 5 and post-4.7 models Jul 11, 2026
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.

2 participants