# AGENT_UI_PATCH_INVALID

<!-- Generated by docs/modules/diagnostics from the package catalogs. Write a guide in docs/diagnostics/<CODE>.md instead of editing this file. -->

`specFromText()` returns `AGENT_UI_PATCH_INVALID` when one patch line of the model's answer cannot apply. It does not throw. The message gives the line number and the problem, and `path` is the `path` of the patch.

## Why it happens

`specFromText()` applies the patches of the answer in order, and stops at the first patch that:

- uses the key `__proto__`, `constructor`, or `prototype` in its `path` or `from`. These keys can change `Object.prototype` on the server, so `specFromText()` refuses them;
- has a `path` or `from` that is not a string;
- moves a value into one of its own descendants;
- is a `test` patch whose value does not match;
- adds a value under a value that is not an object, such as under `null`.

## Fix it

Send the diagnostics back to the model and ask again for the whole spec. The `fix` of the diagnostic shows a correct patch. A patch path names keys of the spec only: `root`, `elements`, `state`, and the keys under them.

## Related

- [`AGENT_UI_SPEC_NOT_FOUND`](https://vitehub.dev/docs/agents/diagnostics/agent_ui_spec_not_found)
- [`AGENT_UI_SPEC_INVALID`](https://vitehub.dev/docs/agents/diagnostics/agent_ui_spec_invalid)

## Source

`AGENT_UI_PATCH_INVALID` belongs to the `agent` package. Its catalog entry is in [`src/ui/diagnostics.ts`](https://github.com/vite-hub/vitehub/blob/main/packages/agent/src/ui/diagnostics.ts#L80).

See [all Agents diagnostics](https://vitehub.dev/docs/agents/diagnostics).

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/agents.md)
- [Define and run](https://vitehub.dev/raw/docs/agents/agent-definitions.md)
- [Instructions and tools](https://vitehub.dev/raw/docs/agents/instructions.md)
- [History and context](https://vitehub.dev/raw/docs/agents/chat-history-sessions.md)
- [Channels](https://vitehub.dev/raw/docs/agents/channels.md)
- [Inspect and evaluate](https://vitehub.dev/raw/docs/agents/observability.md)
- [Advanced](https://vitehub.dev/raw/docs/agents/agent-presets.md)
- [Recipes](https://vitehub.dev/raw/docs/agents/support-agent.md)
- [Presets](https://vitehub.dev/raw/docs/agents/presets.md)
- [Capabilities](https://vitehub.dev/raw/docs/agents/capabilities/access.md)

Next: [AGENT_UI_PROP_INVALID](https://vitehub.dev/raw/docs/agents/diagnostics/agent_ui_prop_invalid.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
