Skip to content

Commit d1ef581

Browse files
feat(validate): catch undefined squad variables and Liquid transfer numbers (#99)
* feat(validate): warn on undefined squad variables Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(validate): reject Liquid transfer destination numbers Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: explain squad variable and transfer number validation Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * docs: link NHS example across stacked PR branches Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent 498332d commit d1ef581

13 files changed

Lines changed: 757 additions & 5 deletions

‎AGENTS.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ Safe to run without asking: `npm run validate`, `npm run audit`,
5353
plain `npm run pull` (it never overwrites local edits), `npm run push -- <org>
5454
--dry-run`, `npm run build`, `npm test`.
5555

56+
- `variable-undefined`: set squad members' `{{vars}}` in squad/member `variableValues`; `--strict` blocks missing values.
57+
- `transfer-number-liquid`: transfer destination numbers must be literal; put per-squad numbers in an inline `transferCall` in `membersOverrides["tools:append"]`.
58+
5659
**2. Never handle API keys.** Don't ask the human to paste a key into chat,
5760
don't print or read out `.env.*` files, never pass a key as a command-line
5861
argument, and never commit `.env.*`. Keys live in `.env.<org>` (gitignored)
@@ -151,6 +154,8 @@ precisely.
151154
never ask for a real key just to validate. Don't weaken the check or the
152155
workflow to get past it, and never edit the state file, `.vapi-ignore` or
153156
`state/<org>/org.json` to make a reference resolve: fix the name, or pull.
157+
- `variable-undefined`: set squad members' `{{vars}}` in squad/member `variableValues`; `--strict` blocks this warning in validate and push.
158+
- `transfer-number-liquid`: use literal transfer numbers; append a per-squad inline `transferCall` in the squad's `membersOverrides["tools:append"]`.
154159
4. **Build PR checks offline** if `vapi-checks.yml` exists:
155160
`npm run check -- --all --dry-run`. Fix anything it reports.
156161
5. **Review the dry-run Name collisions list**, then **deploy only with a yes**

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
221221
| Command | What it does |
222222
| --- | --- |
223223
| `npm run setup` | Connect an org: create `.env.<org>` and `resources/<org>/` |
224-
| `npm run validate -- <org>` | Check resource files offline before deploying |
224+
| `npm run validate -- <org> [--strict]` | Check resource files offline, including undefined squad variables (`variable-undefined`); `--strict` blocks on that warning. `transfer-number-liquid` always errors on Liquid in transfer destination numbers; use per-practice literal numbers (see `examples/nhs-shared-squads`). |
225225
| `npm run apply -- <org>` | Deploy: pull, merge, then preflight and push (the default) |
226226
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits; unknown UUIDs get separate files, never name-linked |
227227
| `npm run push -- <org>` | Preflight the write plan, then push without pulling first (prefer `apply`); `--strict` also blocks validation errors outside the plan. Review `--dry-run` Name collisions, and use `--adopt <id>[=<uuid>]` only with explicit approval to take over a resource; unchanged alias files are removed, edited/unbaselined copies need review. Push/apply support `--json` for one grouped link-preflight report (exit 1 on blockers); see [Running in CI](docs/guides/commands.md#running-in-ci). |

‎docs/guides/blocks.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ A block is a piece of prompt text or config that lives in one file and is
44
used by many resources. Change the block and every assistant and squad that
55
includes it changes with it, in every org.
66

7+
`validate` checks Liquid variables after expanding blocks. For each squad member,
8+
`variable-undefined` warns about root names missing from the member's
9+
`assistantOverrides.variableValues` and the squad's `membersOverrides.variableValues`.
10+
It checks system prompts, first/voicemail/end-call messages, and attached tools,
11+
including `tools:append`. Vapi built-ins, squad tool/handoff extraction schema
12+
properties and alias keys, and Liquid assign/capture/loop locals count as defined.
13+
Raw blocks and tool code are ignored. Standalone assistants are not checked:
14+
their variables can be supplied at call time. This is a static check, not proof
15+
that an extraction tool runs before a variable is used. Use `--strict` with
16+
validate or push to make missing squad variables blocking.
17+
718
There are two kinds:
819

920
| Kind | File | Included with | Use it for |

‎docs/guides/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The other commands are direct only.
1010
| Command | Usage | What it does |
1111
| --- | --- | --- |
1212
| `npm run setup` | `npm run setup [-- <org>]` | Connect an org: creates `.env.<org>` and `resources/<org>/`. |
13-
| `npm run validate` | `npm run validate -- <org>` | Check resource files offline: API shape rules, and that every reference names a file or a state entry. `apply` runs it first. On GitHub Actions, findings are also shown on the files in the pull request. |
13+
| `npm run validate` | `npm run validate -- <org> [--strict]` | Check resource files offline: API shape rules, references, and undefined squad variables. `variable-undefined` warns once per squad member, listing missing root names and where to define them; `--strict` makes this warning blocking in validate and push. `transfer-number-liquid` is always an error: the API rejects Liquid in transfer destination numbers, even with `numberE164CheckEnabled:false`; use per-practice literal numbers, e.g. inline in squad `membersOverrides['tools:append']` (see `examples/nhs-shared-squads`). Covers standalone tools, inline model tools and member/squad appended tools. `apply` runs validation first. On GitHub Actions, findings are also shown on the files in the pull request. |
1414
| `npm run apply` | `npm run apply -- <org> [types or paths] [--adopt <id>[=<uuid>]]` | **The default deploy:** pull, merge, then push. The push preflight below runs before remote writes. See [workflows](workflows.md). |
1515
| `npm run pull` | `npm run pull -- <org> [--force] [--bootstrap]` | Sync platform changes down; never overwrites local edits unless `--force`. |
1616
| `npm run push` | `npm run push -- <org> [--dry-run] [--json] [--strict] [--adopt <id>[=<uuid>]]` | Push without pulling first. Prefer `apply`. Preflight blocks validation errors and unresolved credential names in the write plan (selected resources plus auto-applied dependencies) before any remote mutation, including deletions. `--dry-run` uses the same gate. `--strict` additionally blocks error-severity findings outside the plan; warnings remain advisory. Bootstrap reads may run before preflight. |

‎docs/learnings/squads.md‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ For a one-off call using an existing `squadId`, the same shape can be passed as
156156

157157
## Override Merge Order
158158

159+
### Shared assistants speak unresolved practice variables
160+
161+
**Problem:** A shared assistant says literal `{{name}}` instead of a practice's details.
162+
163+
**Cause:** Undefined variables remain literal on the call; an explicit empty string renders as nothing. Override precedence is member → squad → call; later values win.
164+
165+
**Fix:** Keep assistants shared and set each practice's values in `membersOverrides.variableValues` (or a member's `assistantOverrides.variableValues`). `variable-undefined` warns per squad member; `--strict` blocks it in validate and push. Transfer numbers must stay literal: see [Liquid destination numbers](tools.md#liquid-destination-numbers-fail-api-validation).
166+
167+
### Layer precedence
168+
159169
The final assistant configuration is built by merging these layers in order:
160170

161171
1. Base assistant
@@ -169,8 +179,6 @@ Later layers win on conflicts. `variableValues` from all layers are merged separ
169179

170180
**Gotcha:** a `credentialIds` list anywhere in the squad narrows the whole call to the listed keys, for every member and every provider. A provider left off runs on Vapi's own key with no error. List every key the call needs, and let `npm run validate` check it: see [Credential pins](../guides/credential-pins.md).
171181

172-
**Gotcha:** a variable with no value is **left in the prompt as written**, not replaced and not an error. If a variable isn't in the merged `variableValues`, `{{ myVar }}` reaches the model as the literal text `{{ myVar }}`. A variable that is set to an empty string does render as nothing. So a squad that forgets a variable shows the braces to the model: check every `{{ … }}` in a prompt, and in any [block](../guides/blocks.md) it includes, has a value in each squad that uses it.
173-
174182
---
175183

176184
## Squad-level post-call extraction via `membersOverrides` (multi-member squads)

‎docs/learnings/tools.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ If the schema doesn't meet these requirements, `strict` may be silently disabled
157157

158158
## transferCall Tools
159159

160+
### Liquid destination numbers fail API validation
161+
162+
**Problem:** A transfer destination such as `number: '{{handover_number}}'` is rejected even when the variable is defined.
163+
164+
**Cause:** The API requires E.164 by default; `numberE164CheckEnabled: false` still enforces `^\+?[a-zA-Z0-9]+$`, which rejects Liquid syntax.
165+
166+
**Fix:** Use literal numbers. For shared assistants, put per-squad numbers in an inline `transferCall` in the squad's `membersOverrides["tools:append"]`. `transfer-number-liquid` reports an error before deployment. See [shared squad variables](squads.md#shared-assistants-speak-unresolved-practice-variables) and the [NHS example (PR #100)](https://github.com/VapiAI/gitops/pull/100).
167+
160168
### Forwarding numbers from the assistant are auto-injected
161169

162170
**What you might expect:** Only the `destinations` array on the tool matters.

‎improvements.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,42 @@ have a bootstrap pull leave existing baselines alone.
23532353

23542354
---
23552355

2356+
## 43. Missing practice variables reached live prompts literally
2357+
2358+
Shared assistants can run in many practice squads, each supplying practice
2359+
details through variableValues. A missing value stayed as `{{name}}` on a call.
2360+
`variable-undefined` now checks each squad member's expanded prompts and attached
2361+
tools against squad/member values, Vapi built-ins and runtime assignments. It
2362+
warns by default and blocks with `--strict`. Standalone assistants remain
2363+
unchecked because their values may arrive when a call is created.
2364+
2365+
### Status
2366+
2367+
**Implemented.** Covered by `tests/validate-variables.test.ts`.
2368+
2369+
---
2370+
2371+
## 44. Liquid transfer destination numbers passed offline validation
2372+
2373+
### Problem
2374+
2375+
The API rejects Liquid in transfer number destinations: the default E.164
2376+
validator rejects it, and disabling that check still requires alphanumeric
2377+
characters with an optional leading plus. Runtime template support does not
2378+
make these tool payloads API-valid. A push could therefore fail partway through.
2379+
2380+
### Current behavior and mitigation
2381+
2382+
`transfer-number-liquid` reports an error before deployment for standalone and
2383+
inline transfer tools, including member/squad appended tools. Use literal
2384+
per-practice numbers in inline squad overrides; see `examples/nhs-shared-squads`.
2385+
2386+
### Status
2387+
2388+
**Implemented.** Covered by `tests/validate-transfer-numbers.test.ts`.
2389+
2390+
---
2391+
23562392
## Out of scope (intentionally not improvements)
23572393

23582394
- **State file is identity-only and not git-ignored.** It's intentionally

‎src/validate-cmd.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
BASE_DIR,
1313
loadIgnorePatterns,
1414
RESOURCES_DIR,
15+
STRICT_VALIDATION,
1516
VAPI_ENV,
1617
} from "./config.ts";
1718
import {
@@ -96,7 +97,11 @@ async function main(): Promise<void> {
9697
}
9798
}
9899

99-
const errorCount = findings.filter((f) => f.severity === "error").length;
100+
const errorCount = findings.filter(
101+
(f) =>
102+
f.severity === "error" ||
103+
(STRICT_VALIDATION && f.rule === "variable-undefined"),
104+
).length;
100105
if (errorCount > 0) {
101106
console.error(
102107
`❌ Validation failed with ${errorCount} error(s). Fix the issues above before pushing.`,

‎src/validate-transfer-numbers.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { LoadedResources } from "./types.ts";
2+
import type { ValidationFinding } from "./validate.ts";
3+
4+
export function validateTransferNumbers(
5+
resources: LoadedResources,
6+
): ValidationFinding[] {
7+
const findings: ValidationFinding[] = [];
8+
for (const type of ["tools", "assistants", "squads"] as const) {
9+
for (const resource of resources[type]) {
10+
const visit = (value: unknown, path: string): void => {
11+
if (!value || typeof value !== "object") return;
12+
if (Array.isArray(value)) {
13+
value.forEach((entry, index) => visit(entry, `${path}[${index}]`));
14+
return;
15+
}
16+
const object = value as Record<string, unknown>;
17+
if (
18+
object.type === "transferCall" &&
19+
Array.isArray(object.destinations)
20+
) {
21+
object.destinations.forEach((destination, index) => {
22+
const number = destination?.number;
23+
if (typeof number !== "string" || !/{{|{%/.test(number)) return;
24+
// Vapi: libs/core/src/types/tool.types/transferCallTool.types.ts (TransferDestinationNumber).
25+
findings.push({
26+
severity: "error",
27+
type,
28+
resourceId: resource.resourceId,
29+
rule: "transfer-number-liquid",
30+
fieldPath: `${path ? `${path}.` : ""}destinations[${index}].number`,
31+
message:
32+
"The API rejects Liquid in transfer numbers: E.164 validation applies, and numberE164CheckEnabled:false still requires ^\\+?[a-zA-Z0-9]+$. Use a per-practice literal number, e.g. an inline tool in the squad's membersOverrides['tools:append']; see examples/nhs-shared-squads.",
33+
});
34+
});
35+
}
36+
for (const [key, child] of Object.entries(object)) {
37+
visit(child, path ? `${path}.${key}` : key);
38+
}
39+
};
40+
visit(resource.data, "");
41+
}
42+
}
43+
return findings;
44+
}

0 commit comments

Comments
 (0)