How a Procurement Agent Stopped Making Up Phone Numbers: Plain Code Checks the Facts
A procurement agent compiles contact cards for sales managers, but the model easily invents plausible phone numbers and names. The author did not ask it to "not lie." Instead, he added ordinary code after the model that checks the contacts against the texts the agent actually read. Phone numbers are verified by their 10 digits, names by word stems, and anything not found is removed. Managers do not waste calls on nonexistent numbers.
AI-processed from Habr AI; edited by Hamidun News
Language models are very good at writing plausible data, and that becomes a problem when someone is going to call based on that data. The author of the material on Habr is building an agent that analyzes government procurement for a sales department. The agent opens a procurement card, reads the technical specification and attachments, and if needed goes to the customer's website and checks the publicly available reporting by taxpayer ID (INN). The output is a short card for the manager: what is being purchased, who the customer is, and whom to call. The last item turned out to be the most finicky.
Why asking in the prompt doesn't work
The model knows the format "+7 (495)" followed by seven more digits better than any human does, and it produces "Ivanova Maria Sergeevna, leading specialist" without a hitch. If such a contact ends up in the card, the manager has made a wasted call. After a couple of those, he stops trusting any of the cards.
The first idea was to write in the prompt "do not make up contacts, indicate the source." The author did exactly that, and the model returned a URL and a verbatim quote. But the model writes the quote itself, and it makes errors in it just as confidently as in the number. In effect, the model is checking itself.
So the rule is different: the card may contain only what literally appears in the texts the agent read through its tools. The agent's workflow is not rigid; it chooses for itself what to call: the procurement card, a document in parts, a website page, or reporting. Everything the tools return is assembled into a single tool_text string alongside the model's response. The model has seen this text, but it cannot change it. When the model returns the final JSON, the ground_result function goes through the contacts and discards anything that is not in what was read.
How the code checks phone numbers, names, and email
The same phone number is written differently across documents: "+7 (495) 123-45-67," "8-495-1234567," "tel. 8 495 123 45 67 ext. 228." Comparing strings is pointless, so both the number and the entire text that was read keep only the digits. The leading 7 or 8 and the extension are cut off, leaving ten digits. If those ten digits appear consecutively in the digit-only version of the text, the number is confirmed. If the field contains several numbers separated by ";" or "or," they are split and each is checked separately.
Names are harder because of grammatical cases: a document says "Contact: Ivanova Maria," while the model writes "Ivanova Maria" in the nominative. The code compares stems: for every word of three or more letters, the ending is trimmed, but at least four letters remain. Every word must be found in the text.
This protects against the model's tendency to assemble a person from fragments: a surname from a procurement page, a first name from a signature on a website, or reconstruct a name from an email. For example, "Primerova Elena" might appear out of e.primerova@...
, even though that name is in no document. If even one word is not found, the name is removed entirely. Email is the simplest to check: the lowercase address must appear in full in the text.
Scoring and the decision to send are also handled by code
After the contacts are cleaned, the code reassigns the procurement's rating using the same rules described in the prompt:
- A: a person with a name and a confirmed phone number;
- B: a confirmed phone number without a name;
- C: no confirmed phone number.
If the model assigned a lead verdict but the rating falls to C after verification, the verdict drops to candidate. The procurement is not lost; it stays in the log, but it does not bother people in the chat. There is also a reverse rule: if the model found a reception desk number but decided there was no one to call, the code raises the procurement to lead, unless it is marked as off-profile. A reception desk is also a number, and through it one reaches the right department. Contacts from third-party directory aggregators never receive an A rating, since the person listed there may have stopped handling procurement long ago.
The decision to send takes one line: the card goes to the manager only if the verdict is lead and the rating is A or B. What the model thought about its own rating no longer matters.
Tests, gaps, and conclusion
The verification is covered by ordinary unit tests; the model is not invoked in them. For example, one test substitutes an invented phone number and email and checks that both fields are removed, the rating drops from A to C, and the verdict becomes candidate. There are tests for grammatical cases, extensions, a name taken from an email address, a reference number, and a reception desk. They test the code, not the model's quality: they say nothing about how many contacts the model finds correctly.
The author openly lists the weak points. If everything except digits is stripped from the text, neighboring numbers can run together, so a contract number followed by a date could in theory yield ten suitable digits. The extension is not verified. Name and phone are checked separately, so Ivanova from one page and a number from another will be confirmed even though they have nothing to do with each other. The key point: the code confirms that a number is written in the documents, but whether the right person will answer it can only be checked by making the call.
The practical takeaway for those building agents: let the model read long documents and distinguish the real subject of a procurement from copy-paste boilerplate, but leave the facts a person will act on to deterministic code. A deliberately "dumb" check, meaning ten digits, word stems, and an email substring match, can be read in a minute, and it is immediately clear where it will go wrong. There is no need for a second model or a "rate your confidence from 1 to 10" question.
And one more rule: everything the code corrected in place of the model should be written to a log (in this project, grade_adjusted and removed_unverified), rather than fixed silently. Such a log shows where the prompt explains the task poorly.
- Nov 23, 2026Dwelly's AI Agents Handle 55% of Rental Steps in Britain Without Humans
- Nov 23, 2026Perplexity Launches Teammates: AI Agents Get Whole Job Roles, Not Just Tasks
- Nov 23, 2026Alfa-Bank Executive: AI Agents Accumulate 'Comprehension Debt' Behind Green Tests
- Nov 23, 2026AI Agent Approved a Delayed $3,934 Rent Payment, and a Week Later an Eviction Notice Arrived
Key Questions Answered
Why asking in the prompt doesn't work?
The model knows the format "+7 (495)" followed by seven more digits better than any human does, and it produces "Ivanova Maria Sergeevna, leading specialist" without a hitch. If such a contact ends up in the card, the manager has made a wasted call. After a couple of those, he stops trusting any of the cards. The first idea was to write in the prompt "do not make up contacts, indicate the source." The author did exactly that, and the model returned a URL and a verbatim quote.
How the code checks phone numbers, names, and email?
The same phone number is written differently across documents: "+7 (495) 123-45-67," "8-495-1234567," "tel. 8 495 123 45 67 ext. 228." Comparing strings is pointless, so both the number and the entire text that was read keep only the digits. The leading 7 or 8 and the extension are cut off, leaving ten digits. If those ten digits appear consecutively in the digit-only version of the text, the number is confirmed.
What are the key details on Scoring and the decision to send are also handled by code?
After the contacts are cleaned, the code reassigns the procurement's rating using the same rules described in the prompt: A: a person with a name and a confirmed phone number; B: a confirmed phone number without a name; C: no confirmed phone number. If the model assigned a lead verdict but the rating falls to C after verification, the verdict drops to candidate. The procurement is not lost; it stays in the log, but it does not bother people in the chat.
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.