Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Openai Openai python Response Format Text JSON Schema

From Leeroopedia
Revision as of 13:39, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Openai_Openai_python_Response_Format_Text_JSON_Schema.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains API_Types, Responses_API
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete response type representing a JSON Schema response format configuration for Structured Outputs, provided by the openai-python SDK.

Description

ResponseFormatTextJSONSchemaConfig is a Pydantic model representing a JSON Schema response format used to generate structured JSON responses. It contains a name field (alphanumeric with underscores/dashes, max 64 characters), a schema_ field (aliased from "schema" in JSON) holding the JSON Schema object, a fixed type of "json_schema", an optional description for the model, and an optional strict flag to enforce strict schema adherence. When strict is true, only a subset of JSON Schema is supported. This type is auto-generated from the OpenAI OpenAPI specification by Stainless.

Usage

Import ResponseFormatTextJSONSchemaConfig when inspecting the response format configuration of a completed response that used Structured Outputs with a JSON schema.

Code Reference

Source Location

Signature

class ResponseFormatTextJSONSchemaConfig(BaseModel):
    """JSON Schema response format. Used to generate structured JSON responses."""

    name: str
    schema_: Dict[str, object] = FieldInfo(alias="schema")
    type: Literal["json_schema"]
    description: Optional[str] = None
    strict: Optional[bool] = None

Import

from openai.types.responses import ResponseFormatTextJSONSchemaConfig

I/O Contract

Fields

Name Type Required Description
name str Yes The name of the response format. Must be a-z, A-Z, 0-9, underscores, or dashes (max 64 characters).
schema_ Dict[str, object] Yes The JSON Schema object describing the response format. Aliased from "schema" in JSON.
type Literal["json_schema"] Yes The type of response format. Always "json_schema".
description Optional[str] No A description of the response format, used by the model to determine how to respond.
strict Optional[bool] No Whether to enable strict schema adherence. Only a subset of JSON Schema is supported when true.

Usage Examples

from openai.types.responses import ResponseFormatTextJSONSchemaConfig

# Inspect JSON schema format on a completed response
response = client.responses.create(
    model="gpt-4o",
    input="Extract the name and age from: John is 30 years old",
    text={
        "format": {
            "type": "json_schema",
            "name": "person_info",
            "schema": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "age": {"type": "integer"},
                },
                "required": ["name", "age"],
            },
            "strict": True,
        }
    },
)

# The response text config will be a ResponseFormatTextJSONSchemaConfig
print(response.text.format.name)      # "person_info"
print(response.text.format.strict)    # True

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment