Skip to content

Commit a1e6ffc

Browse files
rng1995claude
andcommitted
fix(providers): apply the control guard on every hosted provider
Resolve sampling parameters for a model: resolve_sampling_parameters now takes the model and runs reject_unsupported_controls itself, so azure_openai (whose registry lists gpt-6.1-sol) gets the temperature guard the other providers already had, and no caller can skip it. The guard raises UnsupportedControlError, a ValueError subclass. GPT-6.1 Sol IDs are read through the same model_name normalizer as Claude IDs (last path segment, lowercased, cut at '@' or ':'), so gpt-6.1-sol:latest, openai/gpt-6.1-sol:nitro and gpt-6.1-sol@2026 are guarded too. A registry entry can declare 'sampling: rejected'. Bedrock reads it, so an application-inference-profile ARN that serves Claude 5.5 can opt in to the temperature guard, as it can already opt out of forced tool calls with 'tool_choice: auto'. The registry-then-name forced tool_choice decision moves into structured_output.forced_tool_choice_supported, and the openai, openai_compatible and bedrock providers delegate to it. create_openai_compatible_chat_model takes forced_tool_choice and builds the disabled_params dict that bind_structured_output looks for in one place. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Narendran Raghavan <[email protected]>
1 parent b10b674 commit a1e6ffc

11 files changed

Lines changed: 195 additions & 68 deletions

File tree

‎src/skillspector/providers/anthropic/provider.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
)
4646
from skillspector.providers import registry
4747
from skillspector.providers.chat_models import (
48-
reject_unsupported_controls,
4948
resolve_reasoning_effort,
5049
resolve_sampling_parameters,
5150
)
@@ -111,8 +110,7 @@ def create_chat_model(
111110
effort = resolve_reasoning_effort()
112111
if effort is not None:
113112
kwargs["effort"] = effort
114-
sampling_parameters = resolve_sampling_parameters()
115-
reject_unsupported_controls(model, sampling_parameters)
113+
sampling_parameters = resolve_sampling_parameters(model)
116114
kwargs.update(sampling_parameters)
117115
chat_model_cls = _ChatAnthropicBearer if _use_bearer_auth() else ChatAnthropic
118116
chat_model = chat_model_cls(**kwargs)

‎src/skillspector/providers/anthropic_proxy/provider.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
)
5959
from skillspector.providers import registry
6060
from skillspector.providers.chat_models import (
61-
reject_unsupported_controls,
6261
resolve_reasoning_effort,
6362
resolve_sampling_parameters,
6463
)
@@ -253,8 +252,7 @@ def create_chat_model(
253252
effort = resolve_reasoning_effort()
254253
if effort is not None:
255254
kwargs["effort"] = effort
256-
sampling_parameters = resolve_sampling_parameters()
257-
reject_unsupported_controls(model, sampling_parameters)
255+
sampling_parameters = resolve_sampling_parameters(model)
258256
kwargs.update(sampling_parameters)
259257
chat_model = _ChatAnthropicProxy(**kwargs)
260258
register_chat_model_controls(

‎src/skillspector/providers/azure_openai/provider.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def create_chat_model(
8484
"max_tokens": max_tokens,
8585
"timeout": timeout,
8686
}
87-
sampling_parameters = resolve_sampling_parameters(include_seed=True)
87+
sampling_parameters = resolve_sampling_parameters(model, include_seed=True)
8888
kwargs.update(sampling_parameters)
8989
chat_model = AzureChatOpenAI(**kwargs)
9090
register_chat_model_controls(

‎src/skillspector/providers/bedrock/model_registry.yaml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# context_length: <int> # total context window in tokens (required)
99
# max_output_tokens: <int> # model's max output cap (optional)
1010
# tool_choice: auto # when the model rejects a forced toolChoice (optional)
11+
# sampling: rejected # when the model rejects temperature (optional)
1112
#
1213
# Keys are public Bedrock model IDs and cross-region inference profile
1314
# IDs. Users can also point SKILLSPECTOR_MODEL at their own
@@ -16,7 +17,9 @@
1617
# models. Add entries here if you have a private ARN you want metadata
1718
# for; an ARN hides the model name, so also declare ``tool_choice: auto``
1819
# when it serves a model that rejects a forced toolChoice (Fable 5.1,
19-
# Mythos 5.1, Opus 5.5, Sonnet 5.5).
20+
# Mythos 5.1, Opus 5.5, Sonnet 5.5), and ``sampling: rejected`` when it
21+
# serves Opus 5.5 or Sonnet 5.5 so SKILLSPECTOR_TEMPERATURE fails before
22+
# any request.
2023

2124
models:
2225
# BedrockProvider's default. The AWS model card lists this suffix-free

‎src/skillspector/providers/bedrock/provider.py‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
3232
Claude models that reject a forced ``toolChoice`` (HTTP 400) get a client
3333
restricted to ``toolChoice`` ``auto``; Bedrock has no JSON-schema output for
34-
them either. See ``forced_tool_choice_supported``.
34+
them either. See ``forced_tool_choice_supported``. A registry entry with
35+
``sampling: rejected`` makes ``SKILLSPECTOR_TEMPERATURE`` fail before any
36+
request for an application-inference-profile ARN that serves Claude 5.5.
3537
"""
3638

3739
from __future__ import annotations
@@ -49,11 +51,8 @@
4951
retained_chat_model_controls,
5052
)
5153
from skillspector.providers import registry
52-
from skillspector.providers.chat_models import (
53-
reject_unsupported_controls,
54-
resolve_sampling_parameters,
55-
)
56-
from skillspector.providers.structured_output import rejects_forced_tool_call
54+
from skillspector.providers.chat_models import resolve_sampling_parameters
55+
from skillspector.providers.structured_output import forced_tool_choice_supported
5756

5857
BEDROCK_DEFAULT_REGION = "us-west-2"
5958
# Cross-region inference profile ID for Claude Sonnet 4.6. Public,
@@ -154,8 +153,7 @@ def create_chat_model(
154153
# JSON-schema outputConfig for them too; bind tools with toolChoice auto
155154
# and let bind_structured_output ask for the call in the prompt.
156155
kwargs["supports_tool_choice_values"] = ("auto",)
157-
sampling_parameters = resolve_sampling_parameters()
158-
reject_unsupported_controls(model, sampling_parameters)
156+
sampling_parameters = resolve_sampling_parameters(model, registry_path=REGISTRY_PATH)
159157
kwargs.update(sampling_parameters)
160158

161159
chat_model = ChatBedrockConverse(**kwargs)
@@ -186,7 +184,4 @@ def forced_tool_choice_supported(self, model: str) -> bool:
186184
application-inference-profile ARN carries no model name, so declare
187185
it in the registry.
188186
"""
189-
declared = registry.lookup_setting(REGISTRY_PATH, model, "tool_choice")
190-
if declared:
191-
return declared != "auto"
192-
return not rejects_forced_tool_call(model)
187+
return forced_tool_choice_supported(model, REGISTRY_PATH)

‎src/skillspector/providers/chat_models.py‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import logging
2121
import os
22-
import re
2322
from urllib.parse import urlparse
2423

2524
from langchain_core.language_models.chat_models import BaseChatModel
@@ -30,17 +29,18 @@
3029
register_chat_model_controls,
3130
retained_chat_model_controls,
3231
)
33-
from skillspector.providers.structured_output import rejects_sampling_controls
32+
from skillspector.providers.structured_output import is_gpt_6_1_sol, rejects_sampling_controls
3433

3534
logger = logging.getLogger(__name__)
3635
MIN_SAMPLING_SEED = -(1 << 63)
3736
MAX_SAMPLING_SEED = (1 << 63) - 1
3837

3938
# Reasoning efforts GPT-6.1 Sol accepts; it rejects ``none`` and ``minimal``.
4039
GPT_6_1_SOL_REASONING_EFFORTS = ("low", "medium", "high", "xhigh", "max")
41-
# GPT-6.1 Sol, bare or behind a gateway namespace or prefix
42-
# (``openai/openai/gpt-6.1-sol``), optionally with a snapshot suffix.
43-
_GPT_6_1_SOL = re.compile(r"(?:^|[/.-])gpt-6\.1-sol(?:-[^/]*)?$")
40+
41+
42+
class UnsupportedControlError(ValueError):
43+
"""A requested sampling or reasoning control the model rejects, raised before any request."""
4444

4545

4646
def resolve_reasoning_effort() -> str | None:
@@ -77,8 +77,19 @@ def resolve_seed() -> int | None:
7777
return seed
7878

7979

80-
def resolve_sampling_parameters(*, include_seed: bool = False) -> dict[str, float | int]:
81-
"""Resolve optional, validated sampling controls for hosted providers."""
80+
def resolve_sampling_parameters(
81+
model: str,
82+
*,
83+
include_seed: bool = False,
84+
reasoning_effort: str | None = None,
85+
registry_path: str | None = None,
86+
) -> dict[str, float | int]:
87+
"""Resolve optional, validated sampling controls for a request to *model*.
88+
89+
Raises :class:`UnsupportedControlError` when *model* rejects the requested
90+
temperature or *reasoning_effort* (see :func:`reject_unsupported_controls`),
91+
so every hosted provider applies the same guard before any request.
92+
"""
8293
parameters: dict[str, float | int] = {}
8394
temperature = resolve_temperature()
8495
if temperature is not None:
@@ -87,33 +98,37 @@ def resolve_sampling_parameters(*, include_seed: bool = False) -> dict[str, floa
8798
seed = resolve_seed() if include_seed else None
8899
if seed is not None:
89100
parameters["seed"] = seed
101+
reject_unsupported_controls(model, parameters, reasoning_effort, registry_path=registry_path)
90102
return parameters
91103

92104

93105
def reject_unsupported_controls(
94106
model: str,
95107
sampling_parameters: dict[str, float | int],
96108
reasoning_effort: str | None = None,
109+
*,
110+
registry_path: str | None = None,
97111
) -> None:
98-
"""Raise ``ValueError`` before any request when *model* rejects a requested control.
112+
"""Raise :class:`UnsupportedControlError` when *model* rejects a requested control.
99113
100-
Any explicit ``temperature``, ``1.0`` included, fails for GPT-6.1 Sol and
101-
the Claude models in ``SAMPLING_REJECTED_MODELS``, which reject sampling
102-
controls. GPT-6.1 Sol also accepts only ``GPT_6_1_SOL_REASONING_EFFORTS``.
114+
Any explicit ``temperature``, ``1.0`` included, fails for GPT-6.1 Sol, the
115+
Claude models in ``SAMPLING_REJECTED_MODELS``, and registry entries at
116+
*registry_path* declaring ``sampling: rejected``. GPT-6.1 Sol also accepts
117+
only ``GPT_6_1_SOL_REASONING_EFFORTS``.
103118
"""
104-
is_gpt_6_1_sol = _GPT_6_1_SOL.search(model.lower()) is not None
119+
sol = is_gpt_6_1_sol(model)
105120
if "temperature" in sampling_parameters and (
106-
is_gpt_6_1_sol or rejects_sampling_controls(model)
121+
sol or rejects_sampling_controls(model, registry_path)
107122
):
108-
raise ValueError(
123+
raise UnsupportedControlError(
109124
f"SKILLSPECTOR_TEMPERATURE is not supported by {model}; unset it to use this model"
110125
)
111126
if (
112-
is_gpt_6_1_sol
127+
sol
113128
and reasoning_effort is not None
114129
and reasoning_effort not in GPT_6_1_SOL_REASONING_EFFORTS
115130
):
116-
raise ValueError(
131+
raise UnsupportedControlError(
117132
f"SKILLSPECTOR_REASONING_EFFORT={reasoning_effort!r} is not supported by {model}; "
118133
f"use one of {', '.join(GPT_6_1_SOL_REASONING_EFFORTS)} or unset it"
119134
)
@@ -149,13 +164,14 @@ def create_openai_compatible_chat_model(
149164
max_tokens: int,
150165
timeout: float | None = 120,
151166
default_headers: dict[str, str] | None = None,
152-
disabled_params: dict[str, object] | None = None,
167+
forced_tool_choice: bool = True,
153168
default_reasoning_effort: str | None = None,
154169
) -> BaseChatModel | None:
155170
"""Create ``ChatOpenAI`` for providers serving OpenAI-compatible endpoints.
156171
157-
*disabled_params* is passed to ``ChatOpenAI``; ``{"tool_choice": None}``
158-
keeps ``with_structured_output`` from forcing a tool call.
172+
``forced_tool_choice=False`` sets ``disabled_params={"tool_choice": None}``
173+
so ``with_structured_output`` never forces a tool call; this is the shape
174+
``llm_utils._binds_unforced_tool_call`` looks for.
159175
"""
160176
if credentials is None:
161177
return None
@@ -170,13 +186,14 @@ def create_openai_compatible_chat_model(
170186
"timeout": timeout,
171187
"default_headers": default_headers,
172188
}
173-
if disabled_params:
174-
kwargs["disabled_params"] = disabled_params
189+
if not forced_tool_choice:
190+
kwargs["disabled_params"] = {"tool_choice": None}
175191
reasoning_effort = resolve_reasoning_effort()
176192
if reasoning_effort or default_reasoning_effort:
177193
kwargs["reasoning_effort"] = reasoning_effort or default_reasoning_effort
178-
sampling_parameters = resolve_sampling_parameters(include_seed=True)
179-
reject_unsupported_controls(model, sampling_parameters, reasoning_effort)
194+
sampling_parameters = resolve_sampling_parameters(
195+
model, include_seed=True, reasoning_effort=reasoning_effort
196+
)
180197
kwargs.update(sampling_parameters)
181198
chat_model = ChatOpenAI(**kwargs)
182199
register_chat_model_controls(

‎src/skillspector/providers/openai/provider.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from skillspector.providers import registry
3131
from skillspector.providers.chat_models import create_openai_compatible_chat_model
32-
from skillspector.providers.structured_output import rejects_forced_tool_call
32+
from skillspector.providers.structured_output import forced_tool_choice_supported
3333

3434
# Documented for completeness — ChatOpenAI defaults here when base_url=None.
3535
OPENAI_DEFAULT_BASE_URL = "https://api.openai.com/v1"
@@ -72,9 +72,7 @@ def create_chat_model(
7272
max_tokens=max_tokens,
7373
timeout=timeout,
7474
default_headers=_resolve_openai_project_headers(),
75-
disabled_params=(
76-
None if self.forced_tool_choice_supported(model) else {"tool_choice": None}
77-
),
75+
forced_tool_choice=self.forced_tool_choice_supported(model),
7876
)
7977

8078
def get_context_length(self, model: str) -> int | None:
@@ -89,8 +87,8 @@ def resolve_model(self, slot: str = "default") -> str:
8987
return user_input or self.SLOT_DEFAULTS.get(slot, "") or self.DEFAULT_MODEL
9088

9189
def forced_tool_choice_supported(self, model: str) -> bool:
92-
"""``False`` when *model* names a Claude model that rejects a forced tool call."""
93-
return not rejects_forced_tool_call(model)
90+
"""``False`` when a registry ``tool_choice: auto`` entry or the Claude model name says so."""
91+
return forced_tool_choice_supported(model, REGISTRY_PATH)
9492

9593
def structured_output_method(self, model: str) -> str | None:
9694
"""``with_structured_output`` method: tool calling when ``tool_choice`` must stay ``auto``."""

‎src/skillspector/providers/openai_compatible/provider.py‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from skillspector.providers import registry
4242
from skillspector.providers.chat_models import create_openai_compatible_chat_model
43-
from skillspector.providers.structured_output import rejects_forced_tool_call
43+
from skillspector.providers.structured_output import forced_tool_choice_supported
4444

4545
REGISTRY_PATH = str(Path(__file__).with_name("model_registry.yaml"))
4646

@@ -72,9 +72,7 @@ def create_chat_model(
7272
credentials=self.resolve_credentials(),
7373
max_tokens=max_tokens,
7474
timeout=timeout,
75-
disabled_params=(
76-
None if self.forced_tool_choice_supported(model) else {"tool_choice": None}
77-
),
75+
forced_tool_choice=self.forced_tool_choice_supported(model),
7876
)
7977

8078
def get_context_length(self, model: str) -> int | None:
@@ -94,10 +92,7 @@ def forced_tool_choice_supported(self, model: str) -> bool:
9492
Without a registry entry, ``False`` when *model* names a Claude model
9593
that rejects a forced tool call.
9694
"""
97-
declared = registry.lookup_setting(REGISTRY_PATH, model, "tool_choice")
98-
if declared:
99-
return declared != "auto"
100-
return not rejects_forced_tool_call(model)
95+
return forced_tool_choice_supported(model, REGISTRY_PATH)
10196

10297
def structured_output_method(self, model: str) -> str | None:
10398
"""``with_structured_output`` method: registry entry, else tool calling for ``tool_choice: auto``."""

0 commit comments

Comments
 (0)