# build_tool_result_payload

> **Function** in `deepagents_code`

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

Build the `tool.result` hook payload (schema documented in `hooks`).

`tool_output` is capped to `HOOK_TOOL_OUTPUT_LIMIT` here so both surfaces
apply the identical cap regardless of where the raw output originates. When
the cap fires the value ends with `TOOL_OUTPUT_TRUNCATION_MARKER` (counted
within the cap, so the result never exceeds the limit) so a consumer can tell
a capped result from a short one. `tool_args` is intentionally not truncated
(see `HOOK_TOOL_OUTPUT_LIMIT`).

## Signature

```python
build_tool_result_payload(
    tool_name: str,
    tool_id: str | None,
    tool_args: dict[str, Any],
    tool_status: ToolStatus,
    tool_output: str,
) -> ToolResultPayload
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `tool_name` | `str` | Yes | The tool that produced the result. |
| `tool_id` | `str \| None` | Yes | The tool-call id, or `None` when it could not be correlated. |
| `tool_args` | `dict[str, Any]` | Yes | The parsed tool-call arguments, or `{}` when uncorrelated. |
| `tool_status` | `ToolStatus` | Yes | `"success"` or `"error"`. |
| `tool_output` | `str` | Yes | The tool's returned content (capped in the payload). |

## Returns

`ToolResultPayload`

The `tool.result` payload dict with `tool_output` capped and marked when
truncation occurred.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/e14e0adcbe78565ed3650e7f24b2a775d5437d25/libs/code/deepagents_code/_tool_stream.py#L652)