> For the complete documentation index, see [llms.txt](https://docs.internetobject.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.internetobject.org/definitions/error-handling.md).

# Error Handling in Definitions

Errors that arise from header definitions and references.

Definitions are resolved after the **entire header** has been read, and references are checked again as data is validated. Two errors are specific to definitions:

| Condition                                | Error code           | Cause                                                            |
| ---------------------------------------- | -------------------- | ---------------------------------------------------------------- |
| Reference to an undefined schema or type | `undefined-schema`   | `$name` is used but no `$name` is defined anywhere in the header |
| Reference to an undefined variable       | `undefined-variable` | `@name` is used but no `@name` is defined anywhere in the header |

> Error codes are stable; messages and positions may vary between implementations. Branch on the code, not the message.

## Undefined schema reference

A `$` reference must name a schema or type defined in the header. An undefined name fails with `undefined-schema`:

```ruby
~ $schema: { name: string, home: $address }
---
~ John, { Main St, NYC }    # ✗ undefined-schema — $address is never defined
```

## Undefined variable reference

A `@` reference must name a variable defined in the header. An undefined name fails with `undefined-variable`:

```ruby
~ $schema: { name: string, isActive: bool }
---
~ John, @active             # ✗ undefined-variable — @active is never defined
```

## Reference order

Because definitions resolve only after the whole header is read, **order within the header is not significant** — a reference MAY appear before the definition it targets. The following resolves even though `$address` is defined after the schema that uses it:

```ruby
~ $schema: { name: string, home: $address }
~ $address: { street, city }
---
~ John, { Main St, NYC }    # ✓
```

For readability you SHOULD still define a reference before you use it; doing so reads top to bottom and makes the dependency obvious.

## See Also

* [Definitions](/definitions/definitions.md) · [Schema References](/definitions/schema-references.md) · [Variables](/definitions/variables.md)
* [Error Model](/parsing-and-errors/error-model.md) — the full error catalogue


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.internetobject.org/definitions/error-handling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
