_normalize_to_model_response() — langchain Function Reference
Architecture documentation for the _normalize_to_model_response() function in factory.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d2970fae_d131_e7b8_2f45_5fcefc4ea166["_normalize_to_model_response()"] fd7a28b1_3772_169b_6524_1342f35143b1["factory.py"] d2970fae_d131_e7b8_2f45_5fcefc4ea166 -->|defined in| fd7a28b1_3772_169b_6524_1342f35143b1 f3b85e63_c3a1_d200_12a5_4dccafed80ff["_chain_model_call_handlers()"] f3b85e63_c3a1_d200_12a5_4dccafed80ff -->|calls| d2970fae_d131_e7b8_2f45_5fcefc4ea166 611bf38d_1c0a_8d53_2a61_0d70eb6cac51["_chain_async_model_call_handlers()"] 611bf38d_1c0a_8d53_2a61_0d70eb6cac51 -->|calls| d2970fae_d131_e7b8_2f45_5fcefc4ea166 style d2970fae_d131_e7b8_2f45_5fcefc4ea166 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/factory.py lines 146–159
def _normalize_to_model_response(
result: ModelResponse | AIMessage | ExtendedModelResponse,
) -> ModelResponse:
"""Normalize middleware return value to ModelResponse.
At inner composition boundaries, ``ExtendedModelResponse`` is unwrapped to its
underlying ``ModelResponse`` so that inner middleware always sees ``ModelResponse``
from the handler.
"""
if isinstance(result, AIMessage):
return ModelResponse(result=[result], structured_response=None)
if isinstance(result, ExtendedModelResponse):
return result.model_response
return result
Domain
Subdomains
Source
Frequently Asked Questions
What does _normalize_to_model_response() do?
_normalize_to_model_response() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/factory.py.
Where is _normalize_to_model_response() defined?
_normalize_to_model_response() is defined in libs/langchain_v1/langchain/agents/factory.py at line 146.
What calls _normalize_to_model_response()?
_normalize_to_model_response() is called by 2 function(s): _chain_async_model_call_handlers, _chain_model_call_handlers.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free