parse() — langchain Function Reference
Architecture documentation for the parse() function in structured_output.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0fda5ec1_1f54_5091_4c3c_0202a78dacb3["parse()"] 7ab19be5_f449_5f71_c0e1_871dfc8e0588["ProviderStrategyBinding"] 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 -->|defined in| 7ab19be5_f449_5f71_c0e1_871dfc8e0588 2e00e1b4_350b_ee3e_5dc5_f7ce23fc8893["parse()"] 2e00e1b4_350b_ee3e_5dc5_f7ce23fc8893 -->|calls| 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 43c7c9c7_b2c0_1dcc_4be8_a8f880c39f25["_extract_text_content_from_message()"] 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 -->|calls| 43c7c9c7_b2c0_1dcc_4be8_a8f880c39f25 2e00e1b4_350b_ee3e_5dc5_f7ce23fc8893["parse()"] 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 -->|calls| 2e00e1b4_350b_ee3e_5dc5_f7ce23fc8893 b2dc3213_a7ed_bba2_9b4e_51f17afe2086["_parse_with_schema()"] 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 -->|calls| b2dc3213_a7ed_bba2_9b4e_51f17afe2086 style 0fda5ec1_1f54_5091_4c3c_0202a78dacb3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/structured_output.py lines 394–420
def parse(self, response: AIMessage) -> SchemaT:
"""Parse `AIMessage` content according to the schema.
Args:
response: The `AIMessage` containing the structured output
Returns:
The parsed response according to the schema
Raises:
ValueError: If text extraction, JSON parsing or schema validation fails
"""
# Extract text content from AIMessage and parse as JSON
raw_text = self._extract_text_content_from_message(response)
try:
data = json.loads(raw_text)
except Exception as e:
schema_name = getattr(self.schema, "__name__", "response_format")
msg = (
f"Native structured output expected valid JSON for {schema_name}, "
f"but parsing failed: {e}."
)
raise ValueError(msg) from e
# Parse according to schema
return _parse_with_schema(self.schema, self.schema_kind, data)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/structured_output.py.
Where is parse() defined?
parse() is defined in libs/langchain_v1/langchain/agents/structured_output.py at line 394.
What does parse() call?
parse() calls 3 function(s): _extract_text_content_from_message, _parse_with_schema, parse.
What calls parse()?
parse() is called by 1 function(s): parse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free