_convert_to_openai_response_format() — langchain Function Reference
Architecture documentation for the _convert_to_openai_response_format() function in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 73843df6_a9a0_a28d_44fd_72611579a443["_convert_to_openai_response_format()"] cfb937d2_ce7f_5338_2b62_6452043ac78a["chat_models.py"] 73843df6_a9a0_a28d_44fd_72611579a443 -->|defined in| cfb937d2_ce7f_5338_2b62_6452043ac78a f73f8b04_5858_f84e_8eb8_98cd9e9ef152["with_structured_output()"] f73f8b04_5858_f84e_8eb8_98cd9e9ef152 -->|calls| 73843df6_a9a0_a28d_44fd_72611579a443 style 73843df6_a9a0_a28d_44fd_72611579a443 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/mistralai/langchain_mistralai/chat_models.py lines 1188–1222
def _convert_to_openai_response_format(
schema: dict[str, Any] | type, *, strict: bool | None = None
) -> dict:
"""Perform same op as in ChatOpenAI, but do not pass through Pydantic BaseModels."""
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_tool(schema, strict=strict)["function"]
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)
):
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
Called By
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/mistralai/langchain_mistralai/chat_models.py.
Where is _convert_to_openai_response_format() defined?
_convert_to_openai_response_format() is defined in libs/partners/mistralai/langchain_mistralai/chat_models.py at line 1188.
What calls _convert_to_openai_response_format()?
_convert_to_openai_response_format() is called by 1 function(s): with_structured_output.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free