Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
feat(responses): enforce strict function tools on /v1/responses (#1030)
Krisztian Gajdarac2d46fd8eaf
diff --git a/COMPATIBILITY.md b/COMPATIBILITY.mdindex 3a24a691b..570985e21 100644--- a/COMPATIBILITY.md+++ b/COMPATIBILITY.md@@ -97,6 +97,12 @@ or undeclared keys.`/v1/chat/completions` routes of a standalone server, because those routesreturn the engine's own tool calls without validating them. Remote-backedmodels pass `strict` to their upstream unchanged.+- **Responses.** `/v1/responses` now accepts `strict: true` on a function tool+ and translates it to the chat tool's `function.strict`, so the rules above+ apply to it. Earlier releases refused it with `400 unsupported_field`. A+ refusal names the Responses field, `tools[i].strict` or `tools[i].parameters`.+ An omitted `strict` is not strict on either route, while OpenAI's Responses+ API tries strict mode whenever the schema allows it.This document defines SIE's compatibility commitments: what constitutes a breaking change, how deprecations are communicated, and what must be true before declaring 1.0.diff --git a/conformance/openai_responses/README.md b/conformance/openai_responses/README.mdindex 5a6f2c1f4..11d52e453 100644--- a/conformance/openai_responses/README.md+++ b/conformance/openai_responses/README.md@@ -127,9 +127,12 @@ and no `type` is a message. The accepted item types are `message`,### Tools and tool_choice- `{"type":"function","name","description"?,"parameters"?,"strict"?}` becomes- `{"type":"function","function":{"name","description"?,"parameters"?}}`.- `strict: false` is accepted and dropped; `strict: true` is refused at- `tools[i].strict`: `strict function schemas are not supported`.+ `{"type":"function","function":{"name","description"?,"parameters"?,"strict"?}}`.+ `strict: true` is kept, and the chat route enforces it on the call's+ arguments; a refusal names `tools[i].strict` or `tools[i].parameters`.+ `strict: false` and `strict: null` are dropped. An omitted `strict` is not+ strict, as on the chat route; OpenAI's Responses API instead tries strict+ mode when the schema allows it.- `{"type":"custom","name","description"?,"format"?}` becomes a function whoseparameters are one required string `input`. `format` is accepted and notenforced. A call to a custom tool comes back as a `custom_tool_call` item.diff --git a/conformance/openai_responses/request_vectors.json b/conformance/openai_responses/request_vectors.jsonindex 95b4de17b..04434cd18 100644--- a/conformance/openai_responses/request_vectors.json+++ b/conformance/openai_responses/request_vectors.json@@ -837,6 +837,41 @@"include_reasoning": false}},+ {+ "name": "strict true reaches the chat tool, strict null is dropped",+ "body": {+ "model": "m",+ "input": "Run ls.",+ "tools": [+ {+ "type": "function",+ "name": "exec_command",+ "description": "Run a shell command.",+ "parameters": {"type": "object", "properties": {"cmd": {"type": "string"}}, "required": ["cmd"], "additionalProperties": false},+ "strict": true+ },+ {"type": "function", "name": "noop", "strict": null}+ ]+ },+ "chat": {+ "model": "m",+ "messages": [{"role": "user", "content": "Run ls."}],+ "stream": false,+ "tools": [+ {+ "type": "function",+ "function": {+ "name": "exec_command",+ "description": "Run a shell command.",+ "parameters": {"type": "object", "properties": {"cmd": {"type": "string"}}, "required": ["cmd"], "additionalProperties": false},+ "strict": true+ }+ },+ {"type": "function", "function": {"name": "noop"}}+ ],+ "include_reasoning": false+ }+ },{"name": "tool_choice auto passes through with tools","body": {@@ -1706,26 +1741,18 @@}},{- "name": "strict function tool",+ "name": "strict function tool as a string","body": {"model": "m","input": "x",- "tools": [- {- "type": "function",- "name": "exec_command",- "description": "Run a shell command.",- "parameters": {"type": "object", "properties": {"cmd": {"type": "string"}}, "required": ["cmd"]},- "strict": true- }- ]+ "tools": [{"type": "function", "name": "exec_command", "strict": "true"}]},"expect": {"status": 400,"type": "invalid_request_error",- "code": "unsupported_field",+ "code": "invalid_request","param": "tools[0].strict",- "message": "tools[0].strict: strict function schemas are not supported"+ "message": "tools[0].strict: Input should be a valid boolean"}},{diff --git a/packages/sie_gateway/openapi.json b/packages/sie_gateway/openapi.jsonindex d0bb05b4f..3c4190e9e 100644--- a/packages/sie_gateway/openapi.json+++ b/packages/sie_gateway/openapi.json@@ -4396,7 +4396,7 @@"description": "``auto``, ``none``, ``required``, or ``{\"type\": \"function\" |\n\"custom\", \"name\"}`` naming a declared tool."},"tools": {- "description": "``function`` tools (``name``, ``description``, ``parameters``,\n``strict`` only ``false``) and ``custom`` tools (``name``,\n``description``, ``format``, which is not enforced), at most 64,\nnames matching ``^[a-zA-Z0-9_-]{1,64}$``. Hosted tool types are\nrefused."+ "description": "``function`` tools (``name``, ``description``, ``parameters``,\n``strict``, which the chat route enforces) and ``custom`` tools\n(``name``, ``description``, ``format``, which is not enforced), at most 64,\nnames matching ``^[a-zA-Z0-9_-]{1,64}$``. Hosted tool types are\nrefused."},"top_p": {"description": "Checked as on ``/v1/chat/completions``.",diff --git a/packages/sie_gateway/src/handlers/responses/request.rs b/packages/sie_gateway/src/handlers/responses/request.rsindex a2fb46734..cbdafcaba 100644--- a/packages/sie_gateway/src/handlers/responses/request.rs+++ b/packages/sie_gateway/src/handlers/responses/request.rs@@ -457,20 +457,11 @@ fn tools(value: Option<&Value>) -> Result<(Vec<Value>, Vec<String>, Vec<String>)&["type", "name", "description", "parameters", "strict"],&path,)?;- match present(tool, "strict") {- None | Some(Value::Bool(false)) => {}- Some(Value::Bool(true)) => {- return Err(ResponsesError::unsupported(- format!("{path}.strict"),- "strict function schemas are not supported",- ))- }- Some(_) => {- return Err(ResponsesError::invalid(- format!("{path}.strict"),- "Input should be a valid boolean",- ))- }+ if !matches!(present(tool, "strict"), None | Some(Value::Bool(_))) {+ return Err(ResponsesError::invalid(+ format!("{path}.strict"),+ "Input should be a valid boolean",+ ));}}let mut function = Map::new();@@ -489,8 +480,13 @@ fn tools(value: Option<&Value>) -> Result<(Vec<Value>, Vec<String>, Vec<String>)"additionalProperties": false,}),);- } else if let Some(parameters) = present(tool, "parameters") {- function.insert("parameters".into(), parameters.clone());+ } else {+ if let Some(parameters) = present(tool, "parameters") {+ function.insert("parameters".into(), parameters.clone());+ }+ if present(tool, "strict") == Some(&Value::Bool(true)) {+ function.insert("strict".into(), Value::Bool(true));+ }}tools.push(json!({"type": "function", "function": Value::Object(function)}));if let Some(name) = tool.get("name").and_then(Value::as_str) {diff --git a/packages/sie_gateway/src/handlers/responses/schema.rs b/packages/sie_gateway/src/handlers/responses/schema.rsindex 24ad3d3ae..839a2b4b8 100644--- a/packages/sie_gateway/src/handlers/responses/schema.rs+++ b/packages/sie_gateway/src/handlers/responses/schema.rs@@ -86,8 +86,8 @@ pub struct ResponsesRequest {#[serde(default, skip_serializing_if = "Option::is_none")]pub stream: Option<bool>,/// ``function`` tools (``name``, ``description``, ``parameters``,- /// ``strict`` only ``false``) and ``custom`` tools (``name``,- /// ``description``, ``format``, which is not enforced), at most 64,+ /// ``strict``, which the chat route enforces) and ``custom`` tools+ /// (``name``, ``description``, ``format``, which is not enforced), at most 64,/// names matching ``^[a-zA-Z0-9_-]{1,64}$``. Hosted tool types are/// refused.#[serde(default, skip_serializing_if = "Option::is_none")]diff --git a/packages/sie_gateway/src/handlers/responses/tests.rs b/packages/sie_gateway/src/handlers/responses/tests.rsindex 7e9cba3dc..9eebb0edd 100644--- a/packages/sie_gateway/src/handlers/responses/tests.rs+++ b/packages/sie_gateway/src/handlers/responses/tests.rs@@ -952,6 +952,70 @@ async fn chat_refusals_name_the_responses_field() {assert!(gateway.dispatcher.dispatched().is_empty());}+const GRAMMAR_CODER_MODEL: &str = "\+sie_id: acme/gcoder+hf_id: acme/gcoder+tasks:+ generate:+ max_output_tokens: 64+ grammar_profile: no-spec+ capabilities:+ tools: true+profiles:+ default:+ adapter_path: sie_server.adapters.sglang:SGLangAdapter+ max_batch_tokens: 8192+ no-spec:+ adapter_path: sie_server.adapters.sglang:SGLangAdapter+ max_batch_tokens: 8192+";++#[tokio::test]+async fn a_strict_function_tool_is_served_on_the_grammar_profile() {+ let gateway = chat_gateway(+ &[GRAMMAR_CODER_MODEL],+ &["acme/gcoder", "acme/gcoder:no-spec"],+ )+ .await;+ let cases = [+ (json!(true), json!("auto"), "acme/gcoder:no-spec"),+ (json!(false), json!("auto"), "acme/gcoder"),+ (json!(true), json!("none"), "acme/gcoder"),+ ];+ for (strict, tool_choice, dispatched_model) in cases {+ let response = proxy_responses(+ State(Arc::clone(&gateway.state)),+ responses_request(json!({+ "model": "acme/gcoder",+ "input": "Run ls.",+ "max_output_tokens": 32,+ "tools": [{+ "type": "function",+ "name": "exec_command",+ "parameters": {"type": "object", "properties": {"cmd": {"type": "string"}}},+ "strict": strict,+ }],+ "tool_choice": tool_choice,+ })),+ )+ .await;+ let status = response.status();+ let body = json_body(response).await;+ assert_eq!(+ status,+ StatusCode::OK,+ "strict={strict} tool_choice={tool_choice}: {body}"+ );+ assert_eq!(body["model"], "acme/gcoder", "{body}");+ let dispatched = gateway.dispatcher.dispatched();+ assert_eq!(+ dispatched.last().map(|work| work.model.as_str()),+ Some(dispatched_model),+ "strict={strict} tool_choice={tool_choice}"+ );+ }+}+#[tokio::test]async fn a_translation_refusal_publishes_nothing() {let gateway = chat_gateway(&[HYBRID_GENERATE_MODEL], &["acme/chat"]).await;diff --git a/packages/sie_sdk/src/sie_sdk/types.py b/packages/sie_sdk/src/sie_sdk/types.pyindex 6ba47831b..c19030766 100644--- a/packages/sie_sdk/src/sie_sdk/types.py+++ b/packages/sie_sdk/src/sie_sdk/types.py@@ -1096,15 +1096,15 @@ ResponseInputItem = (class ResponseFunctionTool(TypedDict):"""A function tool the model may call.- ``strict`` may be omitted or ``False``; strict function schemas are- rejected.+ ``strict: True`` makes the server validate the call's arguments against+ ``parameters``; an omitted ``strict`` is not strict."""type: Literal["function"]name: strdescription: NotRequired[str]parameters: NotRequired[dict[str, Any]]- strict: NotRequired[Literal[False]]+ strict: NotRequired[bool | None]class ResponseCustomTool(TypedDict):diff --git a/packages/sie_server/src/sie_server/api/responses_translation.py b/packages/sie_server/src/sie_server/api/responses_translation.pyindex 8f96df150..5473f21d9 100644--- a/packages/sie_server/src/sie_server/api/responses_translation.py+++ b/packages/sie_server/src/sie_server/api/responses_translation.py@@ -383,18 +383,18 @@ def _tools(value: Any) -> tuple[list[dict[str, Any]], list[str], list[str]]:raise _unsupported(f"{path}.type", f"'{kind}' tools are not supported; send function or custom tools")if kind == "function":_only_keys(tool, _FUNCTION_TOOL_KEYS, path)- strict = tool.get("strict")- if strict is True:- raise _unsupported(f"{path}.strict", "strict function schemas are not supported")- if strict is not None and strict is not False:+ if tool.get("strict") is not None and not isinstance(tool["strict"], bool):raise _invalid(f"{path}.strict", "Input should be a valid boolean")else:_only_keys(tool, _CUSTOM_TOOL_KEYS, path)function = {key: tool[key] for key in ("name", "description") if tool.get(key) is not None}if kind == "custom":function["parameters"] = _custom_tool_parameters()- elif tool.get("parameters") is not None:- function["parameters"] = tool["parameters"]+ else:+ if tool.get("parameters") is not None:+ function["parameters"] = tool["parameters"]+ if tool.get("strict") is True:+ function["strict"] = Truetools.append({"type": "function", "function": function})name = tool.get("name")if isinstance(name, str):diff --git a/packages/sie_ts_sdk/src/types.ts b/packages/sie_ts_sdk/src/types.tsindex 7390a2e61..2a8ecfcf5 100644--- a/packages/sie_ts_sdk/src/types.ts+++ b/packages/sie_ts_sdk/src/types.ts@@ -1741,8 +1741,9 @@ export type ResponseInputItem =| ResponseCustomToolCallOutput;/**- * A function tool the model may call. `strict` may be omitted or `false`;- * strict function schemas are rejected.+ * A function tool the model may call. `strict: true` makes the server+ * validate the call's arguments against `parameters`; an omitted `strict` is+ * not strict.*/export interface ResponseFunctionTool {type: "function";@@ -1750,7 +1751,7 @@ export interface ResponseFunctionTool {description?: string;/** JSON Schema describing the function arguments. */parameters?: Record<string, unknown>;- strict?: false;+ strict?: boolean | null;}/**