Reference sheet · lessons 2, 4, 5, 6

Answer pipeline

FAQ → approved sources → honest fallback → human. The flow, the shapes, the codes, the policy.

Flow

0 · human?phrase list → handoff 1 · FAQscore ≥ t, gap ≥ m 2 · retrieveisAllowedUrl() filter 2 · Claudecitations: enabled grounded?≥1 citation answer 3 · fallback → handoff

Shapes

interface Answer {
  tier: "faq" | "sources" | "fallback";
  text: string;
  citations: { title: string; url?: string; quote?: string }[];
  confidence: number;      // FAQ score, 1 for grounded answers, 0 for fallbacks
  handoff: boolean;        // UI should offer or trigger escalateToHuman()
  reason: string;          // analytics key, see below
}

Reason codes and what they tell you

reasonMeaningWeekly action
visitor-requested-humanTier 0 matched a phraseReview phrases for false positives (“human resources”)
faq:<id>Tier 1 hitSpot-check a sample; watch for near-threshold scores
no-approved-chunksRetrieval found nothing allowedCrawl gap or FAQ gap: add pages to the index or variants to the FAQ
model-declinedClaude replied NOT_IN_SOURCESThe pages do not answer it, or the chunks were poor; check chunking and top-k
insufficient-citationsText without allowed citationsPrompt drift or a citation pointing at a disallowed URL; inspect
groundedTier 2 answered with citationsCelebrate; sample for quality

FAQ dials

strategy (exact | jaccard | tfidf) · threshold (minimum top score, 0..1) · margin (minimum gap to runner-up). Tune on a test set: zero wrong first, then fewest missed.

Grounding prompt (rules)

1. Use only facts that appear in the documents. Do not use outside knowledge, even if you are confident.
2. Cite the documents for every factual sentence.
3. If the documents do not contain the answer, reply with exactly: NOT_IN_SOURCES
   and nothing else. Saying so is the correct answer, not a failure.
4. Be brief and concrete: two to five sentences, plain language, no preamble.
5. Never invent URLs, prices, dates or policy details.

Giving the model explicit permission to say it does not know is Anthropic’s first listed hallucination-reduction technique.Claude docs: reduce hallucinations

Handoff policy (summary)

TriggerUI
Explicit requestOpen the widget now
Any fallbackFallback text + “Talk to a person” button; auto-open on the second fallback in a session
Escalation vocabularyAnswer if possible; always show the button
Near-threshold FAQ hitAnswer + “Did that help?”
Status offlineTicket or email path; never an empty chat

Travels with the visitor: login(userId, hash); attributes bot-last-tier, bot-last-reason; tag and event bot-handoff; drafted summary ending with a session reference (payloads from tawk.to do not include attributes, so the transcript must carry the reference itself).

Where each piece lives

PieceFileLesson
FAQ matcherexamples/src/faq-match.ts4
Allow-list guardexamples/src/allowed-sources.ts5
Claude with citationsexamples/src/grounded-answer.ts5
Orchestrationexamples/src/pipeline.ts6
Secure mode hashexamples/src/tawk-secure-mode.ts2
Webhook handlerexamples/src/tawk-webhook.ts, examples/api/tawk-webhook.ts3
Graph prototypeexamples/src/graph-lite.ts7