Build a Conversational Catalog Search Agent with Guardrails
System DesignModel answerLast updated
Design a multi-step conversational search assistant over a read-only catalog that clarifies intent, enforces hard constraints, grounds answers in records, and falls back safely.
You are asked to design a conversational search assistant. A user describes what they want in plain language, and the system may ask a follow-up question, run searches, compare candidates, and refine its answer over several turns.
Use a read-only product catalog as the example corpus. Users may phrase needs informally (for example, a budget, a use case, and a few "nice to haves"), and every result you show must be backed by records the system is allowed to read. No traffic level, latency target, model, or vendor is given, so state your own assumptions.
Taking actions such as placing an order is out of scope. If you suggest any, describe them as a separate extension with their own contract.
Questions worth raising first
- Which attributes are structured fields, and which exist only in free text?
- Which kinds of requests need a clarifying turn, and which should just return results?
- How fresh must data be, and which fields (price, availability) need an authoritative check before display?
- How do you trade off result quality, factual grounding, latency, and cost?
Part 1: The interaction
Walk through one request from first message to final answer: clarification, retrieval, comparison, and refinement. Explain:
- How the system separates hard constraints from soft preferences.
- How it conveys uncertainty and the absence of good matches.
- How constraints persist across turns and get corrected when the user changes their mind.
Part 2: The agent and retrieval system
Describe the components, the tools the agent can call, and the data flow. Explain how you prevent:
- Claims unsupported by catalog data
- Unbounded tool use
- Stale results
- Retrieved text overriding the agent's instructions
Also say where an agent actually helps, where plain deterministic search is enough, and how you would evaluate the system, including failure modes unique to agent planning.
Hints
Hint 1
Treat the user's request as a structured state object (hard filters, soft preferences, open questions) that is updated each turn, rather than as raw chat history the model must reinterpret.
Hint 2
Let code, not the LLM's prose, enforce hard constraints: the model proposes filters, the search layer applies them, and a validator checks every displayed claim against a record field.
Hint 3
Route simple, well-specified queries straight to conventional search; only invoke the multistep agent when ambiguity, comparison, or reformulation clearly adds value, and cap steps, tokens, and tool calls.
Hint 4
Evaluate against a plain keyword/faceted search baseline, and add agent-specific metrics: unnecessary clarifications, constraint violations, ungrounded claims, loop/step counts, and injection robustness.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
An agent is worth its cost only where a static query box fails: vague goals, tradeoffs, constraints expressed in prose, and iterative refinement. For "red running shoes size 10 under $100", faceted search is faster, cheaper, and more predictable. So the design is a router plus a bounded agent, with deterministic search as both the default and the fallback.
Interaction design
Example flow: "I need a laptop for travel and light video editing, not too expensive."
- Interpret. The model converts the message into a structured state:
- Hard constraints: category = laptop (explicit).
- Soft preferences: lightweight, good for editing.
- Unknowns: budget ceiling, OS preference.
- Clarify only if it changes the result. Ask at most one question, and only if the answer would materially change the candidate set. "Not too expensive" is a good one ("Is there a ceiling, roughly?") because it is a hard filter in disguise. Offer quick-reply options and always allow "skip, show me options".
- Retrieve and present. Show a few results, each with the specific fields that justify it ("1.2 kg, 16 GB RAM, $949") linked to the record.
- Refine. "Actually, under $800" overwrites the budget field in the state. The system states what changed ("Budget updated to $800") so the user can catch misinterpretation.
Hard vs soft: Hard constraints are explicit numbers, categories, or exclusions ("no refurbished"). Soft preferences are adjectives and "nice to have" language. Hard constraints filter; soft ones affect ranking. If the model is unsure which one a phrase is, it either asks or treats it as soft and says so.
Uncertainty and no-match behavior: When nothing satisfies all hard constraints, say so plainly, then offer the closest options with the relaxed constraint named ("Nothing under $800 has 32 GB RAM; these three are $850-$900"). Never silently drop a constraint. If the intent is ambiguous after one clarification, show broad results and invite refinement rather than interrogating the user.
System architecture
Components:
- Router/classifier: decides between direct search and the agent loop (a lightweight model or rules on query length, ambiguity, and comparison words).
- Orchestrator: runs the loop with a step budget (for example 4-6 tool calls), token budget, and wall-clock timeout.
- State store: per-session structured constraints and preferences, plus a short conversation summary.
- Tools (typed, read-only, scoped):
search(filters, query_text, limit)over a hybrid index (BM25 + embeddings, with structured filters).get_item(id)for full records.compare(ids, fields)returning a field-by-field table.check_live(id, fields)for price and stock from the authoritative source.
- Index: structured fields indexed as filterable attributes; descriptions and reviews indexed for text and vector retrieval. Incremental updates via change events keep it near real time.
- Answer builder + validator: composes the response from retrieved records.
Retrieval and ranking
- Apply hard filters in the search engine, not in the prompt. Generated text never decides who passes the constraints.
- Retrieve candidates with hybrid search, then rerank with a cross-encoder or learned ranker using soft preferences as features.
- For attributes found only in text (for example "quiet keyboard"), extract them offline into structured tags with confidence scores, or cite the supporting snippet at answer time.
Preventing the failure modes
- Unsupported claims: The answer builder only receives record fields and snippets. Every factual statement carries a citation to a record ID and field. A validator rejects or strips claims that cannot be matched to retrieved data. Numbers are inserted from records by code instead of being generated.
- Unbounded tool use: Step, token, and time budgets; duplicate-call detection; a tool allowlist; no write permissions. On budget exhaustion, return the best grounded results so far.
- Stale data: Index data may lag, so price and availability are re-fetched via
check_liveright before display. If the check fails, show the item with "price unavailable, verify on page" instead of a cached value presented as current. - Prompt injection: Retrieved text is data, never instruction. Place it in clearly delimited, low-trust fields; tools have no side effects, so injected text cannot cause actions; strip or flag instruction-like patterns; and the validator ensures output matches a schema.
Fallbacks
If the agent times out, errors, or the validator rejects the output, fall back to conventional faceted search with the extracted filters, and tell the user briefly that the results are not conversationally ranked. The user always gets something useful.
Trade-offs
- Each extra agent step adds roughly 1-3 seconds and cost. Keep first-token latency low by streaming the clarification or a progress note.
- More clarification improves precision but fatigues users; cap it at one question per turn and two per session by default.
- Stricter validation reduces hallucinations but may make answers terse.
Evaluation
Offline: a labeled set of queries with relevance judgments. Measure NDCG@k and recall for candidate retrieval, hard-constraint violation rate (target near zero), and groundedness (share of claims supported by cited fields, checked by rules plus an LLM judge with human spot checks).
Agent-specific: clarification necessity (did the question change results?), redundant clarification rate, average steps and tool calls, loop/timeout rate, constraint-carryover accuracy across multi-turn scripts, and injection test suites with poisoned catalog entries.
Online: A/B test against the conventional search baseline. Track task success (click or save of a suitable item), reformulation count, time to success, abandonment, latency, and cost per session. Guardrail metrics: complaint rate and ungrounded-claim rate.
Common mistakes
- Sending every query through the agent.
- Letting the model enforce filters in prose.
- Asking several questions up front.
- Dropping constraints silently when results are sparse.
- Showing cached price or stock as current.
- Trusting retrieved text.
- Evaluating only relevance and ignoring plan-level failures.
Extension: actions
Purchasing or saving would need a separate tool contract: explicit user confirmation, idempotency keys, narrow permissions, and audit logs. It should not share the read-only search path.