search_products
Keyword search over the catalogue. Model names and part numbers are what customers actually type, and BM25 serves those well.
A product-chat assistant for a confidential B2B Shopify store — client name withheld under NDA. It answers product, compatibility and policy questions, and everything is built around one rule: a price or stock level may only come from a live product lookup, and code checks that the model kept to it.
The store already ran an off-the-shelf chatbot, so before writing the agent I measured it. That baseline, and a harder question set it has never seen, is the yardstick this build is judged against.
The store sells specialised B2B equipment and consumables through Shopify, with a catalogue of 1,000+ products. The brief asked for two systems: a product chatbot (recommendations, comparisons, compatibility, order status) and automated ticketing (the chat collects details, verifies them, opens a ticket and emails the office). The constraints were low chat volume, low running cost, and a measurable before and after.
I wrote the requirements document, traced every client requirement to a numbered item, and kept a decision log (D1–D17) so each trade-off has a recorded reason. Then I built the chatbot half as a working prototype.
Scope and confidentiality. The client's name, brand, products and customer data are withheld under NDA, and all tests use synthetic data. Only the chatbot is built; ticketing is designed on paper. The prototype has not been scored by a real model yet, so this page quotes no accuracy number for it. The one measured figure here is the baseline of the tool it would replace.
The store's live chatbot is a third-party product I don't control, so I couldn't fix it, and I didn't want to promise to beat it without knowing the bar. I put 33 questions to it by hand — product facts, policies, contact details, comparisons — and graded each answer on a four-point scale.
| Verdict | Answers | Share |
|---|---|---|
| Correct | 21 | 63.6% |
| Partial | 8 | 24.2% |
| Honest "I don't know" | 4 | 12.1% |
| Wrong | 0 | 0.0% |
| Total | 33 | 100% |
It never made an answer up, which is a real bar, and it handled plain factual questions well. The weakness was seven gaps: store knowledge missing from the catalogue, claims with no source, stale catalogue data, duplicate listings, quote-only products, a hand-off to a human that went unanswered for about eight minutes, and display friction.
That sets the target: not "answer more", but never be wrong, and never be worse than this on any question group. Honest "I don't know" answers are part of the score, so they must not get worse either.
I then wrote 15 harder questions — compatibility, comparison, ambiguity — as a level-3 set the baseline had never seen. It hasn't been run against the existing bot yet, so there is no level-3 baseline.
The chat agent is a LangGraph graph that only wires nodes together; the logic lives in the nodes. Conversation history lives in the checkpointer, keyed by the session id, so the graph itself stays stateless.
begin → agent → (tools → agent)* → finish tool rounds per turn capped at 6 · visitor message capped at 2,000 characters
Keyword search over the catalogue. Model names and part numbers are what customers actually type, and BM25 serves those well.
The live product lookup, and the only source the assistant may quote a price or stock level from.
Store policies, shipping and returns, and contact details, so those answers carry a source instead of a guess.
Records a request for the team with a reference number. It is the only tool that writes anything, and it never touches an order, a price or customer data.
Retrieval is an in-memory BM25 index over the catalogue and policy pages. I kept vector search out of v1 on purpose: it needs an embedding key and a Postgres store, and keyword search is a good fit for part numbers. A VectorStore seam is in place for fusing the two with reciprocal rank fusion once those exist.
A wrong price is the most expensive mistake a B2B store's chatbot can make, so it is designed out in two layers. The prompt tells the model it may only quote a price from a live product lookup in the current turn. Then code verifies it.
The grounding check extracts every dollar amount from the answer and compares it with the amounts in that turn's tool results. Differences and sums of two supported prices are allowed, since a saving or a bundle total is legitimate arithmetic; anything else is flagged. It reports rather than blocks: the answer is already streaming to the visitor, so a flagged turn is logged for review instead of being retracted halfway through.
The store's site intermittently rate-limited requests, even single polite ones. For temporary failures the tool falls back to the catalogue snapshot's price, labelled with the snapshot date, and never states stock because the snapshot has none.
For a delisted or unreadable product there is no fallback. The tool tells the model not to state a price or stock level, and to offer a hand-off instead.
A request records a reason, a summary and an optional contact under a reference number. It is recorded, not yet emailed: notifications belong to the ticketing system, which isn't built.
Business customers can paste things they shouldn't. The first of three planned layers is a rule-based screen that runs before text goes any further. It redacts SSNs, dates of birth, medical-record and insurance numbers, patient names, and card numbers — and a card number only counts if it passes a Luhn check, so an order number or phone number isn't mistaken for one.
The result never contains the removed text, only the kind that was found. The same screen runs on hand-off requests, so nothing sensitive is written to disk. It is deliberately aggressive about redacting, because a false positive costs one retyped sentence, and honest about its limits: a patient name with no context word beside it isn't caught.
A bug the tests caught. A date of birth written 04/12/1980 came out as [DATE OF BIRTH]80, leaking the last two digits of the year, because the pattern matched a two-digit year before the four-digit one. The fix tries four digits first, with a regression test. The other two layers — a small-model detector and a flag for staff review — are designed, not built.
The agent talks to one interface, LLMProvider, not to a vendor SDK. Two adapters implement it: Anthropic's Messages API, and an OpenAI-compatible Chat Completions adapter that covers OpenRouter and Gemini's compatible endpoint.
A FallbackProvider takes an ordered list of routes, each a provider plus a model, and hands the turn to the next one when a route fails. It only does that if the failure came before any text reached the visitor. After that, the error is raised as is, because answering again would repeat the start of the reply.
On a 429 the adapter backs off and honours Retry-After instead of hammering the vendor.
Parallel tool calls stay apart per vendor, double-quoted arguments are accepted, and a model's raw tool syntax is never shown to the visitor.
Requests through the aggregator ask for no data collection. A new vendor still needs a written decision record before real customer data goes near it.
The client preview page and the chat endpoint need a demo token, compared in constant time and held in an HttpOnly cookie. Chat answers 401 without it.
A sliding window of 20 messages a minute per client, reading the real client address through the proxy so every visitor doesn't share one quota.
A setting or a file on disk turns chat off with a 503, without a redeploy.
A non-root Docker image with one worker, a VPS stack behind HTTPS, and a smoke test that passes against the container and through the proxy.
186 tests pass on a clean checkout of the prototype branch, which I ran just before writing this page, and the linter is clean. Three import-linter contracts keep the architecture honest rather than documented: chat and ticketing never import each other, lower packages never import the API or either system, and the database layer stays at the bottom.
An eval runner (make eval) puts the 48 questions to a real model and writes a report for human grading: first-token latency, which tools were called, whether the price was live or from the snapshot, expected-keyword coverage, flags for unsupported amounts, and a per-question "must not say" list. Verdicts use the baseline's own four-point scale so the two are directly comparable.
The eval runner has only been exercised against a scripted server. Answer quality, latency and cost on a real model are the next measurement, which is why this page quotes none.
BM25 is strong on part numbers and weak on paraphrase. Vector search and the Postgres store are designed with a seam in place, not built.
The ticketing flow is specified, with code rather than the LLM validating completeness, but not implemented. The shop widget is a static preview page, not the planned React component.
It runs on synthetic data. Hand-off requests are recorded, not emailed, and the vendor decision record has to exist before production traffic.
The code is in a private repository. I'm happy to walk through it live.
Get in touch