# Guided intake demo: source

> The code that makes the Guided intake demo work, walked through snippet by snippet.

A script runs the claim in fixed phases. The model collects the answers, and gates decide when the claim moves on.

## A script is a list of phases

Each phase has a name and a job. The visitor sees them in the **View script** panel.

```json file=demos/guided-intake/script/guided-intake-claim-flow.json
"phases": [
  {
    "id": "welcome",
    "name": "Welcome and triage",
    "description": "Greets the visitor, offers what the assistant can do, and works out what happened and how urgent it is. Any incident details the visitor gives along the way go straight into the claim file.",
    …
```

## Answers have a schema

The model records what it hears, and the platform checks each value before storing it.

```json file=demos/guided-intake/script/guided-intake-claim-flow.json
"emergency_status": {
  "description": "How urgent it is right now: emergency, urgent or not_urgent.",
  "schema": { "type": "string", "enum": ["emergency", "urgent", "not_urgent"] }
}
```

## Gates move the claim on

The first gate that passes picks the next phase. The model never moves the claim itself.

```json file=demos/guided-intake/script/guided-intake-claim-flow.json
{
  "when": { "$and": [ { "$bind": "data.incident_type" }, { "$bind": "data.emergency_status" } ] },
  "to": "incident"
}
```

## A step that always runs

On entry to the cover phase, the script calls the cover check itself, so it is never skipped.

```json file=demos/guided-intake/script/guided-intake-claim-flow.json
{
  "id": "check",
  "heading": "Check the claim against the sample policy",
  "do": { "$call": { "function": "guided-intake-check-cover", "input": { "incident_type": { "$bind": "data.incident_type" }, "cost_band": { "$bind": "data.cost_band" } } } },
  …
},
```
