***

title: toDict
slug: /reference/typescript/agents/context-builder/to-dict
description: Convert all contexts to a dictionary for SWML generation.
max-toc-depth: 3
---------------------

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

Convert all contexts to a dictionary for SWML generation. Calls `validate()`
first and throws `Error` if the configuration is invalid.

## **Returns**

`Record<string, unknown>` -- A mapping of context names to their serialized dictionaries,
ready for inclusion in the SWML document.

## **Example**

```typescript {7}
import { ContextBuilder } from '@signalwire/sdk';

const builder = new ContextBuilder();
const ctx = builder.addContext('default');
ctx.addStep('greet').setText('Hello!');

const data = builder.toDict();
// {"default": {"steps": [{"name": "greet", "text": "Hello!"}]}}
```