Warn with `UnsupportedSettingWarning` when a model ignores a setting like `timeout`, `max_retries` or `stop_sequences`
Written by Claude (Douwe's coding agent) at Douwe's request.
- Closes #10502
Why
A model ignores a ModelSettings field it doesn't support. That's right for tuning knobs like temperature, but some fields are guarantees: Bedrock ignores timeout and max_retries, OpenAIResponsesModel (what openai: resolves to) ignores stop_sequences, Google ignores parallel_tool_calls=False. Ignoring those silently changes behavior in ways that only show up in production.
Each model class now declares the generic settings it ignores, and Model.prepare_request emits an UnsupportedSettingWarning when a request sets timeout, max_retries, stop_sequences, parallel_tool_calls=False (with function tools), extra_headers or extra_body on a model that ignores it. The timeout warning points to request_timeout. Tuning knobs stay silent. Nothing raises.
New public surface
pydantic_ai.UnsupportedSettingWarning(UserWarning)(also inpydantic_ai.exceptions)ModelSettingName, aLiteralof theModelSettingsfield namesModel.unsupported_settings: ClassVar[frozenset[ModelSettingName]], empty by default, so custom model classes never warn until they declare it
User-visible behavior
agent = Agent('bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0', model_settings={'timeout': 10})
agent.run_sync('hi')
# before: no timeout applied, no signal
# after: UnsupportedSettingWarning: The `timeout` setting is not supported by model 'bedrock:...' and will be
# ignored. Use `request_timeout` instead, which Pydantic AI enforces for every model.
Decisions for Douwe
- Warn wherever the setting comes from (run, agent, capability, model
settings), not only run-level. Settings are merged before they reach the model, so provenance isn't available without threading it through, and an agent-level guarantee is as much a guarantee as a run-level one. TheFallbackModelconcern is narrower than it looks:FallbackModel.prepare_requestis a pass-through, so only a candidate that is actually tried warns, and the fix (set the setting on the other candidates' ownsettings) is whatdocs/retries.mdalready recommends. Docs and the skill now say so. extra_headers/extra_bodyare in, warn-only.- Left out:
max_tokens(only dropped by Codex on purpose, where usage isn't billed per token, and by decision models; the harness and MCP sampling set it themselves, so it would warn on values the user never chose) andtool_choice(explicit forcing already raises through thesupports_forced_tool_choiceprofile flags). Mistral honorsmax_retries=0only and is treated as supporting it. - Decision models leave
max_tokens,stop_sequencesandparallel_tool_callsundeclared: they write no text and make at most one tool call, so those hold without being sent. - A request warns once, from the model that sends it: framework code that only prepares a request (output-mode resolution, span attributes,
FallbackModelper-candidate parameters, the pre-flight token count, all of which can run in a Temporal workflow) is wrapped in a privateContextVarsuppression.OpenAIResponsesModel.compact_messagesis a separate request and warns again. - The
stop_sequencesan MCP server's sampling request sends don't warn (the server chose them); other settings on the sampling model still do.
Verification
test_supported_by_lists_match_the_wirenow also asserts each class's declaration equals what itsSupported by:lists (pinned to the wire) leave out, and that it warns for exactly the guarantee settings it ignores.- Setting source and scope:
test_warns_wherever_the_setting_comes_from,test_tuning_knobs_and_unset_or_supported_settings_stay_silent,test_a_model_that_declares_nothing_never_warns,test_warns_once_per_request. - Specific cases:
test_parallel_tool_calls_warns_only_when_false_and_tools_are_offered,test_fallback_model_warns_only_for_the_models_it_tries,test_openai_profile_adds_ignored_settings,test_mcp_sampling_stays_silent_about_the_servers_stop_sequences,test_model_setting_name_lists_every_model_settings_field.
What changes for existing users
Users who set one of these settings on a model that ignores it now see a warning; with warnings configured as errors (e.g. pytest -W error), that becomes a failure until they move or drop the setting.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.
🤖 Generated with Claude Code