Skip to content

Commit be939df

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 f1039e1 commit be939df

14 files changed

Lines changed: 762 additions & 6 deletions

‎AGENTS.md‎

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

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

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
210210
| Command | What it does |
211211
| --- | --- |
212212
| `npm run setup` | Connect an org: create `.env.<org>` and `resources/<org>/` |
213-
| `npm run validate -- <org>` | Check resource files offline before deploying |
213+
| `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`). |
214214
| `npm run apply -- <org>` | Deploy: pull, merge, then push (the default) |
215215
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits |
216216
| `npm run push -- <org>` | Push without pulling first (prefer `apply`) |

‎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]` | **The default deploy:** pull, merge, then push. 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] [--strict]` | Push without pulling first. Prefer `apply`. `--strict` aborts before any API call if validation finds an error. |

‎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
@@ -2334,6 +2334,42 @@ have a bootstrap pull leave existing baselines alone.
23342334

23352335
---
23362336

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

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

‎src/push.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,11 @@ async function main(): Promise<void> {
18371837
} else {
18381838
console.log(" ✅ No validation issues.");
18391839
}
1840-
const errorCount = findings.filter((f) => f.severity === "error").length;
1840+
const errorCount = findings.filter(
1841+
(f) =>
1842+
f.severity === "error" ||
1843+
(STRICT_VALIDATION && f.rule === "variable-undefined"),
1844+
).length;
18411845
if (errorCount > 0) {
18421846
if (STRICT_VALIDATION) {
18431847
console.error(

‎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)