開發或採購 AI 聊天機械人前,如何用 YAML 範本和驗證器寫好一頁規格
Write a one-page spec before you build (or buy) an AI chatbot, with a YAML template and a validator
文章提供一份用於開發或採購 AI 聊天機械人的一頁 YAML 規格範本,以及一個 50 行 Python 驗證器,要求項目先明確列出範圍、指標和交接規則等內容。
When an AI chatbot project goes over budget, the cause is rarely the model. It's scope that was never written down: which questions the bot answers, which systems it touches, who it hands over to, and how anyone will know it's working. Two developers quote the "same" chatbot and one is three times the other, because they imagined different bots.
The fix is boring and effective: a one-page spec, in a format you can lint. This post gives you a YAML template we use at the start of chatbot work, and a 50-line Python validator that refuses to let a spec through until the expensive questions are answered.
What belongs in a chatbot spec?
Seven sections cover almost every project:
- Goal and metric. One sentence on the job ("answer order and returns questions on the store website") and one number you'll track (for example, the share of conversations resolved without a person).
- Channels. Website widget, WhatsApp, Instagram, an internal Slack bot. Each channel is its own integration and its own set of rules.
- Knowledge sources. Help centre, policies, product feed, past tickets. Note who owns each one and how often it changes.
- Actions. Anything the bot does rather than says: look up an order, book an appointment, create a ticket. Actions turn a chatbot into an agent, and they are where most build time goes.
- Hand-over rules. When the bot stops and passes the conversation to a person, and to which queue.
- Off-limits topics. Things it must never discuss or promise (legal advice, discounts it can't grant, medical claims).
- Test set. At least 30 real past questions with the answer you expect, including awkward ones.
The template
goal: "Answer order, delivery and returns questions on the store website"
metric:
name: resolved_without_human
target: 0.5
channels: [website]
languages: [en]
knowledge_sources:
- name: help_centre
owner: support_lead
refresh: weekly
- name: returns_policy
owner: ops_manager
refresh: on_change
actions:
- name: order_status
system: shopify
auth: order_number_plus_email
handover:
- trigger: customer_asks_for_human
queue: support
- trigger: refund_over_limit
queue: support_senior
off_limits: [legal_advice, discounts_not_in_policy]
test_set: tests/golden_questions.csv
A validator that blocks vague specs
import csv, sys, yaml
REQUIRED = ["goal", "metric", "channels", "knowledge_sources",
"handover", "off_limits", "test_set"]
def check(path):
spec = yaml.safe_load(open(path))
errors = [f"missing: {k}" for k in REQUIRED if not spec.get(k)]
for src in spec.get("knowledge_sources", []):
if not src.get("owner"):
errors.append(f"knowledge source '{src.get('name')}' has no owner")
for act in spec.get("actions", []) or []:
if not act.get("auth"):
errors.append(f"action '{act['name']}' has no auth rule")
triggers = {h.get("trigger") for h in spec.get("handover", [])}
if "customer_asks_for_human" not in triggers:
errors.append("handover must include customer_asks_for_human")
target = spec.get("metric", {}).get("target")
if not isinstance(target, (int, float)) or not 0 < target <= 1:
errors.append("metric.target must be a share between 0 and 1")
test_file = spec.get("test_set")
if test_file:
try:
rows = list(csv.DictReader(open(test_file)))
if len(rows) < 30:
errors.append(f"test set has {len(rows)} questions, need 30+")
except FileNotFoundError:
errors.append(f"test set not found: {test_file}")
return errors
if __name__ == "__main__":
problems = check(sys.argv[1])
for p in problems:
print("FAIL", p)
sys.exit(1 if problems else 0)
Run it in CI next to the bot's code, and the spec stays honest as the project grows. When someone adds a WhatsApp channel or a refund action, the validator asks the follow-up questions for you.
Why each check exists
- Owners on knowledge sources. Stale content is the most common reason a bot gives a wrong answer after launch. A named owner means someone gets the ticket when the returns policy changes.
- Auth on every action. An order-status lookup without verification is a data leak. Decide the rule (order number plus email, a signed-in session) before writing the tool.
- "Ask for a human" is mandatory. Customers will ask. A bot that argues with them costs more in complaints than it saves.
- A numeric target. Without one, "is it working?" becomes an opinion.
- Thirty test questions. Fewer, and you can't tell a real improvement from noise when you change prompts or models.
Using the spec to compare quotes
Send the same spec to every developer or vendor. You'll get quotes you can actually compare, and the gaps become obvious: one quote leaves out the Shopify action, another assumes you'll write the test set yourself. The spec also tells you whether you need a custom build at all. If the answer is "website only, help centre only, no actions", an off-the-shelf help desk bot may be enough.
If you'd rather have someone else run this process end to end, this is the kind of work our AI chatbot development team does for businesses in the USA, UK, Canada and Australia.
FAQ
How long should the spec be?
One page. If it doesn't fit, the first version is too big; split it into phases.
Who should write the test questions?
The support team, from real tickets. Developers write questions the bot already answers well.
Does this work for voice agents too?
Yes. Add a latency_budget and a call-transfer number to the hand-over section.
來源:DEV Community · dev.to