Commit 2224a3d
[FIX] Strip deprecated sampling params for Claude Opus 4.7 (#1934)
* Removed temperature parameter for claude opus 4.7 models
* [FIX] Strip sampling params on Vertex AI path and anchor model regex
Address review feedback on the Opus 4.7 sampling-param strip:
- VertexAILLMParameters.validate() now returns the stripped dict, so
Claude Opus 4.7 routed through Vertex AI (vertex_ai/claude-opus-4-7@...)
no longer sends temperature/top_p/top_k.
- Model pattern is now an anchored regex
(`claude-opus-4-7(?=$|[-:@/v])`) so prefix collisions like
claude-opus-4-70, claude-opus-4-75 do not silently strip sampling
params from unrelated future models. The allowed delimiters cover
every real id format: date suffix, Vertex @<date>, ARN paths, v1:0
version tag, and end-of-string.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [FIX] Tighten Opus 4.7 sampling-strip and add test coverage
Address PR #1934 review:
- HIGH: anchor regex no longer admits `v`-prefixed alpha continuations.
`(?=$|[-:@/v])` accepted `claude-opus-4-7verbose`/`vnext`/`variant`.
Switched to `(?=$|[-:@/]|v\d)` — keeps `v1` / `v9` version tags valid,
rejects bare-`v` continuations.
- HIGH: `_strip_deprecated_sampling_params` now logs a debug breadcrumb
when sampling params are present but no model id field matches. This
is the silent-skip path for opaque Bedrock AIP ARNs / Azure Foundry
deployments that omit the model id — operators hitting the upstream
400 now have a way to confirm detection was attempted-and-skipped vs
never attempted.
- MED: helper no longer mutates its input. Returns a shallow copy,
matching the file's `result_metadata = adapter_metadata.copy()` style.
- MED: docstring documents the contract change — returned dict may
omit the `temperature` key. Consumers must use `.get("temperature")`.
Grepped platform-service / SDK / workers / backend for direct
`["temperature"]` reads; only one consumer accesses it and uses
`.get()` already, so no caller-side change needed today.
- LOW: comment drift — `substring-matched` → `regex-searched`; misleading
route-prefix bullet rewritten as "leading text passes through because
the regex is anchored only at the trailing edge"; docs URL switched
from `platform.claude.com` (console host) to `docs.claude.com`
(canonical docs host); docstring extends top_p/top_k strip rationale;
redundant Foundry inline comment removed (helper docstring covers it).
- MED: new `tests/test_sampling_strip.py` (57 cases) pins
- 23 positive id formats (native, Bedrock foundation/cross-region/ARNs,
Vertex `@<date>`, Azure deployments, dot/underscore separators,
`v\d` version tags)
- 18 negatives including prefix collisions (`4-70`, `4-75`, `4-79`,
`4-71-...`) and bare-`v` continuations (`4-7verbose`/`vnext`/`variant`)
- copy-not-mutate, all-three-params strip, AIP fallback via both
`model` and `model_id`, double-opaque limitation + debug log,
quiet-no-op for non-deprecated models
- parametrized end-to-end strip across all four adapters
(Anthropic, Bedrock, Azure AI Foundry, Vertex AI) — locks the
Vertex AI gap that surfaced in this PR's review.
All 278 sdk1 tests pass (221 pre-existing + 57 new).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [FIX] Resolve D205 by splitting docstring summaries
The pre-commit.ci auto-fix moved the closing `"""` to its own line but
left the multi-line summary intact, so D205 still flagged three
docstrings on test_sampling_strip.py:158/177/234. Rewrite the three as
single-line summary + blank + body so D205 actually passes. Also let
ruff normalize the import block.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* [FIX] Use pytest.approx for float equality (SonarCloud reliability)
SonarCloud flagged four `== 0.5` checks against temperature reads in
test_sampling_strip.py as "Do not perform equality checks with floating
point values". Switch to `pytest.approx(0.5)` to match the project
convention (test_gemini_adapter.py:42 uses the same form). Reword one
trailing comment as a leading comment to keep the assertion under the
90-char line limit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* [FIX] Narrow strip-skipped breadcrumb to opaque AIP ARNs only
Greptile flagged that `BaseChatCompletionParameters.temperature` declares
`default=0.1`, so Pydantic's `model_dump()` always emits `temperature` —
the previous `elif any(p in result for p in _DEPRECATED_SAMPLING_PARAMS)`
fired for every routine call through these adapters (claude-3-5-sonnet,
claude-opus-4-6, gpt-4o, …), producing log noise that mimicked a failed
strip attempt.
Replace the guard with `_looks_like_opaque_aip_arn(...)` keyed off the
`application-inference-profile` substring — the one concrete case where
the model id is genuinely unrecoverable from the string and the upstream
will 400 if the underlying foundation model is Opus 4.7+. Add a
regression test (`test_strip_does_not_log_when_sampling_params_present_
but_model_not_opaque`) that locks the no-noise invariant for the routine
case.
The existing test that exercises the breadcrumb path
(`test_strip_skipped_when_both_fields_opaque_and_logs_debug`) still
passes because both fields hold AIP ARNs.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent aae622b commit 2224a3d
2 files changed
Lines changed: 427 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
18 | 139 | | |
19 | 140 | | |
20 | 141 | | |
| |||
462 | 583 | | |
463 | 584 | | |
464 | 585 | | |
465 | | - | |
| 586 | + | |
466 | 587 | | |
467 | 588 | | |
468 | 589 | | |
| |||
646 | 767 | | |
647 | 768 | | |
648 | 769 | | |
649 | | - | |
| 770 | + | |
| 771 | + | |
650 | 772 | | |
651 | 773 | | |
652 | 774 | | |
| |||
735 | 857 | | |
736 | 858 | | |
737 | 859 | | |
738 | | - | |
| 860 | + | |
739 | 861 | | |
740 | 862 | | |
741 | 863 | | |
| |||
945 | 1067 | | |
946 | 1068 | | |
947 | 1069 | | |
948 | | - | |
| 1070 | + | |
| 1071 | + | |
949 | 1072 | | |
950 | 1073 | | |
951 | 1074 | | |
| |||
0 commit comments