***

title: validate
slug: /reference/python/agents/context-builder/validate
description: Validate the entire context configuration tree.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

Validate the entire context configuration. Called automatically during SWML
rendering, but can be called manually to catch errors early.

Checks performed:

* At least one context exists.
* A single context is named `"default"`.
* Every context has at least one step.
* All step-level `valid_steps` references point to steps that exist within the
  same context (the special value `"next"` is always allowed).
* All `valid_contexts` references at the context level point to contexts that
  exist in the builder.
* All `valid_contexts` references at the step level point to contexts that exist
  in the builder.
* All `gather_info` configurations have at least one question, no duplicate keys,
  and valid `completion_action` targets.

## **Returns**

`None` -- Raises `ValueError` with a descriptive message if validation fails.

## **Example**

```python {10}
from signalwire import AgentBase

agent = AgentBase(name="my-agent", route="/agent")

contexts = agent.define_contexts()
ctx = contexts.add_context("default")
ctx.add_step("greet").set_text("Hello!")

try:
    contexts.validate()
except ValueError as e:
    print(f"Invalid context config: {e}")

agent.serve()
```