From 8ce551effdd92d9d6f2ecf13a187551bf45a1a3f Mon Sep 17 00:00:00 2001 From: Dev Sharma <12devsharma10c@gmail.com> Date: Tue, 5 Aug 2025 00:01:49 +0530 Subject: [PATCH] Support full JSON Schema types in structured outputs response_format Relax schema validation for structured outputs (response_format=json_schema) - Updated structured output schema validation to allow any valid JSON Schema (arrays, primitives, nested types), not just function-call style objects. - Maintains backward compatibility with existing function-calling schemas. Fixes: #1733 --- .../resources/chat/completions/completions.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/openai/resources/chat/completions/completions.py b/src/openai/resources/chat/completions/completions.py index c851851418..a74cdafbd5 100644 --- a/src/openai/resources/chat/completions/completions.py +++ b/src/openai/resources/chat/completions/completions.py @@ -1,5 +1,4 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. - from __future__ import annotations import inspect @@ -163,6 +162,24 @@ class MathResponse(BaseModel): print("answer: ", message.parsed.final_answer) ``` """ + response_format = { + "type": "json_schema", + "json_schema": { + "name": "string_list_wrapper", + "schema": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": {"type": "string"} + } + }, + "required": ["items"], + "additionalProperties": False + } + } +} + _validate_input_tools(tools) extra_headers = {