pretty_repr() — langchain Function Reference
Architecture documentation for the pretty_repr() function in ai.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD de27f2dc_4c99_d3b6_840e_8023575c79ee["pretty_repr()"] de5a7878_b3fe_95d7_2575_7f534546dc1e["AIMessage"] de27f2dc_4c99_d3b6_840e_8023575c79ee -->|defined in| de5a7878_b3fe_95d7_2575_7f534546dc1e style de27f2dc_4c99_d3b6_840e_8023575c79ee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/messages/ai.py lines 349–410
def pretty_repr(self, html: bool = False) -> str:
"""Return a pretty representation of the message for display.
Args:
html: Whether to return an HTML-formatted string.
Returns:
A pretty representation of the message.
Example:
```python
from langchain_core.messages import AIMessage
msg = AIMessage(
content="Let me check the weather.",
tool_calls=[
{"name": "get_weather", "args": {"city": "Paris"}, "id": "1"}
],
)
```
Results in:
```python
>>> print(msg.pretty_repr())
================================== Ai Message ==================================
Let me check the weather.
Tool Calls:
get_weather (1)
Call ID: 1
Args:
city: Paris
```
""" # noqa: E501
base = super().pretty_repr(html=html)
lines = []
def _format_tool_args(tc: ToolCall | InvalidToolCall) -> list[str]:
lines = [
f" {tc.get('name', 'Tool')} ({tc.get('id')})",
f" Call ID: {tc.get('id')}",
]
if tc.get("error"):
lines.append(f" Error: {tc.get('error')}")
lines.append(" Args:")
args = tc.get("args")
if isinstance(args, str):
lines.append(f" {args}")
elif isinstance(args, dict):
for arg, value in args.items():
lines.append(f" {arg}: {value}")
return lines
if self.tool_calls:
lines.append("Tool Calls:")
for tc in self.tool_calls:
lines.extend(_format_tool_args(tc))
if self.invalid_tool_calls:
lines.append("Invalid Tool Calls:")
for itc in self.invalid_tool_calls:
lines.extend(_format_tool_args(itc))
return (base.strip() + "\n" + "\n".join(lines)).strip()
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does pretty_repr() do?
pretty_repr() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/ai.py.
Where is pretty_repr() defined?
pretty_repr() is defined in libs/core/langchain_core/messages/ai.py at line 349.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free