> 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

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 | `schema-not-defined`   | `$name` is used but no `$name` is defined anywhere in the header |
| Reference to an undefined variable       | `variable-not-defined` | `@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 `schema-not-defined`:

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

## Undefined variable reference

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

```ruby
~ $schema: { name: string, isActive: bool }
---
~ John, @active             # ✗ variable-not-defined — @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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
