# format_agent_exception

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/remote_client/format_agent_exception)

Render an exception from `RemoteAgent.astream` for the UI.

The LangGraph server serializes non-allowlisted exceptions as
`{"error": <ExceptionType>, "message": <text or "An internal error occurred">}`
(see `langgraph_api.serde`). `RemoteGraph` wraps that dict in
`RemoteException(payload)`, so the default `str(exc)` renders as an ugly
Python dict repr in the UI.

## Signature

```python
format_agent_exception(
    exc: BaseException,
) -> str
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `exc` | `BaseException` | Yes | The exception caught from the agent stream. |

## Returns

`str`

`"<ErrorType>: <message>"` for `RemoteException` dict payloads,

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/0412009c5441bef8d75a427e1da8909e33ab5b56/libs/code/deepagents_code/remote_client.py#L75)