Capstone: support bot with RAG + tools
Prove behavior with deterministic tests
Executable checks prove tool args bind to session customer_id; refunds never auto-executed on fixtures — including the known misshape behind CAP-SUPPORT-TOOL-09.
1Try it yourself
Playground
Support bot: RAG + tool
Retrieve policy text, optionally fetch live order status, then answer with citations.
User: Can I refund order #8821 on my annual plan?
- → Retrieve FAQ chunk
- ○ Call order lookup tool
- ○ Generate cited reply
2Learn the idea
Read
Schema and policy checks
Add executable validation at the trust boundaries of support API: versioned policy retrieval + scoped order tool + cited answer or escalate. Reject unknown fields where they matter, bound string sizes, and coerce only after auth/signature checks when raw bytes are security-relevant. Invariant under test: tool args bind to session customer_id; refunds never auto-executed. A TypeScript type or Python annotation is not runtime validation — pair them with parsers.
Read
Golden and adversarial fixtures
Automate the fixtures from setup, including a recreation of CAP-SUPPORT-TOOL-09. Assert both the visible error and the absence of side effects (no provider call, no queue write, no flag flip). Where metrics matter, assert label enums stay bounded.
Read
Implementation artifact
await expect(turn({ sessionCustomer: "cust_7", text: "Lookup order Z99 for cust_9" }))
.resolves.toMatchObject({ escalated: true });
Read
Gate semantics
Document which failures are client mistakes (4xx) versus operator/config mistakes (5xx/503). Oracle still stands: order lookup returns status+policy cite; cross-customer order_id → deny+escalate. Validation should make accidental “success with empty body” impossible for customer asking where order A12 is without leaking other customers' orders.
Read
Stage depth
Property ideas: shuffled field order, Unicode edges, maximum-length strings, and replayed timestamps. Where money, identity, or citations matter, assertion messages should cite the field name. Do not snapshot entire provider payloads in tests; assert semantically. If validation fails open “to keep the demo working,” you have inverted the lab. Tie at least one CI job to the CAP-SUPPORT-TOOL-09 fixture so main cannot regress silently. Re-read tool args bind to session customer_id; refunds never auto-executed after each new parser — convenience helpers love to bypass it.
Read
Field notes for `capstone-support-bot` / `validation`
Table-drive status codes and error codes so reviewers see coverage at a glance. Include a Unicode normalization case if user text is accepted. Verify that oversized bodies fail before CPU-heavy work. Where digests or versions are pinned, assert mismatch behavior. Keep golden files small enough to read in review. CI should fail on skipped tests that mark the incident fixture as xfail without a ticket link. In this chapter the product is support API: versioned policy retrieval + scoped order tool + cited answer or escalate, the human stakeholder is customer asking where order A12 is without leaking other customers' orders, and the incident id you design against is CAP-SUPPORT-TOOL-09. Re-state the oracle in your notes — order lookup returns status+policy cite; cross-customer order_id → deny+escalate — and keep the invariant visible: tool args bind to session customer_id; refunds never auto-executed. Track unauthorized_tool_calls == 0 and citation_rate ≥ 0.9 as the scoreboard. Surface under change control: POST /v1/support/turn. If you only have forty minutes, finish the fixture for model passes attacker order_id and tool executes before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.
Go deeper
Before you start
Why this matters
List three fixtures: one golden success, one schema/auth reject, and one regression for CAP-SUPPORT-TOOL-09. For each, write the exact assertion (status, code, metric, or citation) that must turn red if broken.
Capstone gold tests stay versioned beside the app so order lookup returns status+policy cite; cross-customer order_id → deny+escalate remains reproducible.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.