_oai_structured_outputs_parser() — langchain Function Reference
Architecture documentation for the _oai_structured_outputs_parser() function in base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e0312c85_0499_1106_d885_0930ecb0fc4f["_oai_structured_outputs_parser()"] 2b046911_ea21_8e2e_ba0d_9d03da8d7bda["base.py"] e0312c85_0499_1106_d885_0930ecb0fc4f -->|defined in| 2b046911_ea21_8e2e_ba0d_9d03da8d7bda style e0312c85_0499_1106_d885_0930ecb0fc4f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/chat_models/base.py lines 3681–3710
def _oai_structured_outputs_parser(
ai_msg: AIMessage, schema: type[_BM]
) -> PydanticBaseModel | None:
if parsed := ai_msg.additional_kwargs.get("parsed"):
if isinstance(parsed, dict):
return schema(**parsed)
return parsed
if ai_msg.additional_kwargs.get("refusal"):
raise OpenAIRefusalError(ai_msg.additional_kwargs["refusal"])
if any(
isinstance(block, dict)
and block.get("type") == "non_standard"
and "refusal" in block["value"] # type: ignore[typeddict-item]
for block in ai_msg.content_blocks
):
refusal = next(
block["value"]["refusal"]
for block in ai_msg.content_blocks
if isinstance(block, dict)
and block["type"] == "non_standard"
and "refusal" in block["value"]
)
raise OpenAIRefusalError(refusal)
if ai_msg.tool_calls:
return None
msg = (
"Structured Output response does not have a 'parsed' field nor a 'refusal' "
f"field. Received message:\n\n{ai_msg}"
)
raise ValueError(msg)
Domain
Subdomains
Source
Frequently Asked Questions
What does _oai_structured_outputs_parser() do?
_oai_structured_outputs_parser() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/base.py.
Where is _oai_structured_outputs_parser() defined?
_oai_structured_outputs_parser() is defined in libs/partners/openai/langchain_openai/chat_models/base.py at line 3681.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free