_convert_to_openai_response_format() — langchain Function Reference
Architecture documentation for the _convert_to_openai_response_format() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1b8cb178_42d5_1a67_7602_8228794247a8["_convert_to_openai_response_format()"] 2b046911_ea21_8e2e_ba0d_9d03da8d7bda["base.py"] 1b8cb178_42d5_1a67_7602_8228794247a8 -->|defined in| 2b046911_ea21_8e2e_ba0d_9d03da8d7bda 8e1c6ba4_0c19_ddac_8d04_68d2a775e1c4["bind_tools()"] 8e1c6ba4_0c19_ddac_8d04_68d2a775e1c4 -->|calls| 1b8cb178_42d5_1a67_7602_8228794247a8 f144b7f2_8059_57ad_4c98_4b3d77c48244["with_structured_output()"] f144b7f2_8059_57ad_4c98_4b3d77c48244 -->|calls| 1b8cb178_42d5_1a67_7602_8228794247a8 a129387a_a0b1_9985_0b43_bfc1f161529a["_construct_responses_api_payload()"] a129387a_a0b1_9985_0b43_bfc1f161529a -->|calls| 1b8cb178_42d5_1a67_7602_8228794247a8 style 1b8cb178_42d5_1a67_7602_8228794247a8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/chat_models/base.py lines 3641–3678
def _convert_to_openai_response_format(
schema: dict[str, Any] | type, *, strict: bool | None = None
) -> dict | TypeBaseModel:
if isinstance(schema, type) and is_basemodel_subclass(schema):
return schema
if (
isinstance(schema, dict)
and "json_schema" in schema
and schema.get("type") == "json_schema"
):
response_format = schema
elif isinstance(schema, dict) and "name" in schema and "schema" in schema:
response_format = {"type": "json_schema", "json_schema": schema}
else:
if strict is None:
if isinstance(schema, dict) and isinstance(schema.get("strict"), bool):
strict = schema["strict"]
else:
strict = False
function = convert_to_openai_function(schema, strict=strict)
function["schema"] = function.pop("parameters")
response_format = {"type": "json_schema", "json_schema": function}
if (
strict is not None
and strict is not response_format["json_schema"].get("strict")
and isinstance(schema, dict)
and "strict" in schema.get("json_schema", {})
):
msg = (
f"Output schema already has 'strict' value set to "
f"{schema['json_schema']['strict']} but 'strict' also passed in to "
f"with_structured_output as {strict}. Please make sure that "
f"'strict' is only specified in one place."
)
raise ValueError(msg)
return response_format
Domain
Subdomains
Source
Frequently Asked Questions
What does _convert_to_openai_response_format() do?
_convert_to_openai_response_format() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/base.py.
Where is _convert_to_openai_response_format() defined?
_convert_to_openai_response_format() is defined in libs/partners/openai/langchain_openai/chat_models/base.py at line 3641.
What calls _convert_to_openai_response_format()?
_convert_to_openai_response_format() is called by 3 function(s): _construct_responses_api_payload, bind_tools, with_structured_output.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free