The Most Useful Bug in Our LLM Assistant Was in the System Prompt
I built a role-scoped AI chat assistant for a B2B telecom platform. Customers ask about their contracts, invoices, tickets and memberships in plain language. Staff get a second assistant with a different disclosure polic
I built a role-scoped AI chat assistant for a B2B telecom platform. Customers ask about their contracts, invoices, tickets and memberships in plain language. Staff get a second assistant with a different disclosure policy. Both run on Laravel and React, with Claude or OpenAI behind one provider interface.
The unit tests were green. Then we ran a hand-graded evaluation of 87 real questions, and the most instructive failure turned out to live in the system prompt itself.
The architecture: the model is a router and a phraser
The core rule of the design is that the model never holds customer data. We call the layer that enforces this the Assistant Data Layer (ADL).
When the model wants data, it emits a tool call such as get_contracts(type?). Arguments only. The backend then:
- derives the customer scope from the auth token, never from a tool argument
- calls the real portal controller the UI already uses
- keeps only whitelisted fields, then runs a forbidden-field scanner that aborts the request instead of returning a payload if anything sensitive slips through
- caches the full role-scoped rowset server-side under an owner-bound handle
The model receives only this:
{ "summary": "...", "dataset_ref": "...", "columns": [...], "preview": "at most 5 rows" }
The table renders from the backend straight to the browser, and the CSV export is built server-side. Raw rows never enter the model context, which cuts token cost and shrinks what the provider ever processes.
A second guard, ReplyGuard, checks the figures in the final reply against the data the tools actually returned. That way it catches fabricated numbers, not just leaked ones.
The eval: 87 questions, graded by hand
We wrote 87 questions the way real users ask them and ran them against the assistant with the production model configuration. Every answer was graded by hand against the governing prompt rule and checked against the database.
First run: 60/87 passing (69%).
Rather than patch answers one by one, we traced the sixteen outright failures back to their source. They collapsed into nine root causes: lookup misses, formatting rules the model did not follow, and one that was more interesting than the rest.
The bug: a worked example the model treated as data
The system prompt contained a worked example showing how a good answer should look. It had concrete numbers in it, because examples with numbers feel clearer.
The model read that example as data. For some questions it answered straight from the example's figures and never called a tool. The answer was fluent, well formatted and wrong. Worse, it looked exactly like a correct answer, so only grading against the database exposed it.
This is a quiet failure class. Nothing errors. No guard fires on a leak, because nothing private leaked. The model simply found an answer closer than the tool.
The fix: no real figures in the prompt, enforced by a test
We rewrote the few-shot examples with placeholder tokens instead of plausible figures: [Amount], [Date], [ID].
Then we added an automated test on the prompt itself: PromptTest extracts every integer and dollar figure from the prompt strings and fails the build if any of them looks like a valid contract value. The prompt cannot drift back to having sample figures in it.
The other eight fixes
The remaining eight root causes were mostly prompt hygiene and contract tightening:
- Clarification thresholds: The model asked for clarification when it could have inferred the sensible default. We lowered the threshold for reading contract status.
-
Date arithmetic: The model calculated renewal dates itself instead of asking the backend. Added a dedicated
renewals_duefilter on the contract tool. - Empty-state phrasing: When a customer had zero overdue invoices, the model sometimes apologized for an error. Standardized empty result handling.
- Tool routing collisions: Two tools had overlapping descriptions. Separated their docstrings with explicit mutual exclusions.
- Multi-turn state drift: Follow-up questions lost the customer scope filter. Persisted the session boundary explicitly in the thread state.
- Currency formatting: The model dropped cent values inconsistently. Enforced strict formatting in the view layer rather than asking the LLM to format.
- Negative assertions: Questions like "Do I have any unpaid bills?" sometimes triggered a generic yes. Added explicit negative test fixtures.
- Forbidden field masking: Fixed a race condition where masked fields were returned in dev logs.
The result: 79/87 (91%)
On the second run against the same 87 questions:
- 79/87 passed (91%)
- 21/21 confidentiality and adversarial prompts passed clean, with zero customer data leaks
- The 8 remaining failures were aesthetic phrasing differences that did not affect business accuracy
What I learned
- Few-shot examples are data. If you put a realistic figure in a system prompt, the model will eventually quote it back to a user as fact. Use placeholders or abstract schemas.
- Never pass customer scope through tool arguments. Always derive the scope from the authenticated session server-side.
- Hand-grade your first 100 eval cases. Automated LLM-as-a-judge is useful later, but grading the first set by hand is how you find architectural flaws like prompt pollution.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.