Layered Script Design for AI Customer Service Chatbots: A Practical Guide

    This guide explains why putting greetings, product answers, policies, follow-ups, and handoffs into a single prompt fails, and how to fix it with a six-layer script design. You will learn how to define each layer's triggers, outputs, and human handoff rules, how to generate layer-specific replies and Q&A entries with an LLM, and how to validate the result using coverage, accuracy, and handoff metrics on real conversation replays. The article also includes a sample JSON configuration, a comparison of mixed versus layered scripts, and cloud implementation notes.

    1. Background: Why a Single Mixed Script Fails

    When many teams first build a customer service bot, they put greetings, product explanations, after-sales policies, payment reminders, and closing lines into one prompt and expect the model to “figure it out.” In production, the problems cluster into five types:

    1. Layers are mixed together. Every stage shares one tone and one logic. Users cannot tell which stage they are in, and the bot does not know what it is supposed to do.
    2. Intents are not decomposed. A single request often has a dozen phrasings. If only the standard phrasing is maintained, any variant that fails to match falls back to a generic reply.
    3. Answers have no boundaries. Content about pricing, policies, and commitments is not annotated with conditions, so the model tends to “fill in” rules that do not exist and over-answers.
    4. Human handoff is unclear. Which questions must be escalated, when to escalate, and what context to pass along are not defined in advance, so the risk lands on frontline agents.
    5. There are no acceptance criteria. Teams review one or two demo conversations but do not measure coverage or failure types, so issues cannot be traced to a specific layer.

    The shared root cause is this: conversation flow design is mistaken for prompt writing. The essence of layered scripts is to break a vague generation task into several subtasks that each have a single responsibility and can be judged and validated.

    2. Step 1: Define the Six Layers and Their Boundaries

    Before writing any prompt, draw the flow skeleton. A four-column table is a practical way to fix each layer: layer, trigger, output, and handoff rule. Mark unconfirmed information explicitly as “TBD” instead of leaving it blank.

    Layer Trigger Output Handoff rule
    Welcome Session start, or reactivation after a long silence Identity statement + capability scope + one guiding question Not applicable
    Intent recognition Any user input Intent label + confidence + missing slots Hand off when confidence is below the threshold
    Standard reply Intent is clear and slots are complete Verifiable factual answer Hand off when beyond the knowledge boundary
    Clarification Slots are missing or ambiguous One closed-ended question at a time Hand off after two consecutive failed clarifications
    Human handoff A mandatory handoff item is matched Handoff summary + confirmed information + expected wait Is itself a handoff
    Closing and follow-up Issue is resolved or the user signals the end Recap of the conclusion + satisfaction confirmation Hand off if the user expresses dissatisfaction

    You must also maintain a separate mandatory handoff list, for example: disputes over amounts and refund decisions, legal and compliance commitments, account security and identity verification, explicit user requests for a human, intense emotions or escalating complaints, and two consecutive intent recognition failures by the model. Write this list explicitly into the system constraints rather than relying on the model’s “good judgment.”

    3. Step 2: Generate Layer-Specific Scripts and Q&A Entries with an LLM

    Once the skeleton is set, use an AI coding tool or a large language model to generate content layer by layer. The key constraints are: each layer handles only one type of input, answers must not invent policies, anything uncertain is marked “hand off to human,” and each intent lists at least three phrasings.

    Each layer entry should contain five fields: trigger, standard script, replaceable variables, forbidden expressions, and example phrasings. A sample structured configuration looks like this:

    1. {
    2. "layer": "standard_reply",
    3. "trigger": "intent=refund_policy AND slot.order_paid=true",
    4. "reply_template": "Order {order_id} is paid. The refund rule is {policy_text}, effective {effective_date}",
    5. "variables": ["order_id", "policy_text", "effective_date"],
    6. "forbidden": ["refund is guaranteed", "refund anytime", "valid forever"],
    7. "fallback": "transfer_to_human"
    8. }

    Three practical points:

    • Expand variants at the intent layer. For each intent, maintain four sample types: standard phrasing, synonymous rewrites, colloquial omissions, and typo tolerance. Use variants as classification input rather than exact matching.
    • Write only verifiable content at the reply layer. Prices, policies, and timeframes must include applicable conditions and effective dates. When a condition is missing, output “TBD” and hand off to a human instead of producing a plausible-looking number.
    • List forbidden expressions explicitly. Putting commitment phrasings that the model tends to generalize into a prohibition list works better than patching them afterward with prompt tweaks.

    4. Step 3: Validate with Coverage, Accuracy, and Handoff Rate

    Validation must replay real conversation samples, not have a person eyeball a few cases. Build four core metrics and one experience metric:

    • High-frequency question coverage: the share of top-N high-frequency questions that are correctly recognized and answered;
    • Answer accuracy: the share of answers that match verifiable entries in the knowledge base;
    • Average number of clarifications: reflects the quality of intent recognition and slot design;
    • Handoff rate and false handoff rate: the right cases must be escalated, and the wrong ones must not be;
    • Whether the user knows the next step: at the end of the session, can the user state the conclusion and the follow-up action.

    When a metric misses the target, trace the script issue to a specific layer and entry, for example “the intent recognition layer triggers inaccurately on ‘how long until it arrives,’” “one answer in the standard reply layer exceeds the boundary,” or “the human handoff layer does not cover account security questions.” Then fix layer by layer and run regression tests. Put the regression case set under version control and run it on every change to avoid breaking three things while fixing one.

    5. Common Pitfalls and a Side-by-Side Comparison

    Dimension Mixed script Six-layer script
    Starting point One block answers everything Define layers and boundaries first
    Intent Only the standard phrasing Covers multiple phrasings
    Answers Easily overstep boundaries Conditions and timeframes annotated
    Handoff Unclear boundaries Separate rules and list
    Validation Reviewing a single conversation Coverage, accuracy, and handoff rate
    Typical problem Answers that miss the question Each layer does one thing

    6. Engineering Implementation Notes

    On the cloud, general-purpose service categories can carry each stage: use a message queue to absorb conversation event spikes, object storage to keep script versions and regression samples, a logging service to record every intent decision and handoff reason, and monitoring and alerting to notify in real time when the handoff rate spikes or accuracy drops. The general cloud product categories offered by Baidu AI Cloud can be combined along these lines, but the specific selection should be evaluated against your own traffic and compliance requirements.

    The conclusion is clear: mixing everything together only yields generic replies, while layering yields a customer service flow you can validate. Define the layers and boundaries first, generate content second, and validate with data last. These three steps cannot be skipped.