[1.x] Honor the Strict attribute on Mistral and OpenRouter tools
#[Strict] on a tool currently only reaches OpenAI, xAI and Anthropic (#1219). Mistral and OpenRouter both accept strict on Chat Completions function definitions, but the shared MapsChatCompletionTools trait never sends it.
- Mistral:
Function.strict(boolean, defaultfalse) in https://docs.mistral.ai/openapi.yaml - OpenRouter:
ChatFunctionTool.function.strict("Enable strict schema adherence") in https://openrouter.ai/openapi.yaml
Changes
MapsChatCompletionToolsgets asupportsStrictTools()switch,falseby default. When it returnstrueand the tool has#[Strict], the function definition getsstrict: true.MistralGatewayandOpenRouterGatewayturn the switch on.- Tools without the attribute go out exactly as before, with no
strictkey. - Groq, Cohere, DeepSeek and OpenAI-compatible gateways are unchanged: Groq documents
strictonly onresponse_format, Cohere uses a top-levelstrict_toolsflag, and DeepSeek requires thehttps://api.deepseek.com/betabase URL for strict mode.
#[Strict]
class LookupOrder implements Tool { /* every field ->required() */ }
agent(tools: [new LookupOrder])->prompt('Where is order 42?', provider: 'mistral');
OpenRouter and Claude models
OpenRouter forwards strict to models that support it. For Claude models it also needs the x-anthropic-beta: structured-outputs-2025-11-13 header: "Without this header, OpenRouter will strip the strict field and route normally" (provider selection). Apps can already send it through the provider's headers config, so this PR doesn't add it automatically.
// config/ai.php
'openrouter' => [
'driver' => 'openrouter',
'key' => env('OPENROUTER_API_KEY'),
'headers' => ['x-anthropic-beta' => 'structured-outputs-2025-11-13'],
],
Behaviour change
Tools that already carry #[Strict] now send strict: true on Mistral and OpenRouter. OpenAI models reached through OpenRouter apply OpenAI's strict rules, so a strict tool with an optional field is rejected there, the same as on the OpenAI provider today.
Live check
- Mistral (
mistral-small-latest): strict tool accepted, called with{"min":1,"max":10}. A strict tool with an optional field is also accepted. - OpenRouter: pending. The test key hit its spend limit (403) before the run.
Tests
- Mistral and OpenRouter: a
#[Strict]tool sends the full function definition withstrict: true; a tool without the attribute has nostrictkey. - Groq: a
#[Strict]tool still has nostrictkey.