Using LLMs to Surface Silent Business Defects in Code
Silent defects are harder to catch than syntax errors. A clean compile, green unit tests, and a page that loads only prove the current path does not crash. Under-counted amounts, dates that slip across a month boundary, and fields renamed on one side while the other still reads the old structure often surface only during reconciliation, customer complaints, or an audit. An LLM offers a fresh reading perspective and can restate "under what preconditions this code is actually correct," but it cannot guess the files, runtime environment, and business rules it cannot see. This article explains how to scope an LLM review, which questions to ask, where the model helps reliably, what it cannot replace, and how to design tests that pin down silent errors.
Silent defects are harder to catch than syntax errors. A clean compile, green unit tests, and a page that opens only prove the current path does not crash. Under-counted amounts, dates that slip across a month boundary, or a field renamed on one side while the other still reads the old structure often surface only during reconciliation, customer complaints, or an audit. An LLM can offer a different reading perspective and restate “under what preconditions is this code actually correct,” but the files, runtime environment, and business rules it cannot see must not be filled in by guessing.
1. Separate the three categories first
The first category is local defects: a wrong variable, an inverted condition, an unhandled null, or an abnormal result for a special input. When you provide the function together with its calling convention, the model can usually point out the risks.
The second category is composition defects: a coupon and a spend-threshold discount are each correct alone, but stack into a double deduction or the wrong order; dates behave normally day to day, yet break at month-end, across a year boundary, or in a leap year. If unit tests only cover “each used on its own,” the defect stays hidden for a long time.
The third category is contract defects: one side changes a field name or unit while the other still reads the old format. Each file looks fine in isolation; only when assembled does it fail. These depend on context, and a small snippet in a chat window is usually not enough.
2. What to provide during a review
An effective review is not tossing code into a dialog box and hoping for luck; it is narrowing the range the model has to guess.
Goals and invariants: for example, “the amount paid must never be negative; the same discount must not be counted twice; the priority between coupon and spend-threshold follows the business rules.” Without invariants, the model can only talk about style and cannot judge correctness.
Relevant implementation: the pricing function, the discount rules, the callers, and the field definitions. If you paste only the final formula, the model cannot see where the data comes from.
Known constraints: which inputs are already validated upstream and which this function must defend against. Otherwise the model treats “duplicate validation” as a must-fix, or mistakes a real hole for something “already guaranteed upstream.”
Failure samples: an order that uses both a coupon and a spend-threshold discount, a leap-year February 29, a read/write after a field rename. Samples constrain far better than adjectives.
The scope it can access: if the tool only sees the current file, do not treat its conclusions as a whole-repo review. A project-level review must confirm which modules and tests it actually read; do not equate “pasting into a conversation” with “reading the repository.”
3. Drive with boundary questions, not just “are there bugs?”
Ask specific questions. For example: when both discounts are present, what is the deduction order; does spend-threshold-then-coupon or coupon-then-spend-threshold match the rules; is the discount base the original price or the already-reduced amount; are amounts stored as floats or integer cents; at which step does rounding happen.
For dates, ask: is the time zone fixed; does “month-end” mean the calendar month-end or 30 days; is February in a leap year written as 28; does a cross-day comparison treat dates as strings.
Across modules, ask: do the write-side and read-side fields share the same name, unit, and nullability; when a field is missing, does it fail, skip, or silently use a default.
Illustration (to show the idea only, not a specific product interface):
Rule: spend-threshold and coupon can stack; apply spend-threshold first, then the coupon;the coupon discount is based on the post-threshold amount, in cents.Please list: uncovered input combinations, branches where a double deduction could occur,and assertions that need to be added.Do not change the business priority; only point out paths that conflict with the rule above.
4. Where the model helps reliably
It is well suited to checklist-style review: nulls, boundaries, whether branches are symmetric, whether errors are swallowed, whether comments contradict the implementation. With the relevant files placed together, it can also try to trace call relationships, for example “the write side already renamed the field, the read side still uses the old name.”
Its other value is breaking the author’s blind spots. Staring at the same code for a long time turns historical conventions into reasonable-sounding assumptions. When restating the control flow, the model often asks “did this branch miss something.” This does not mean it is always right: the developer may know the function only receives validated data, in which case the constraint should be written into a comment or a type rather than mechanically validated again.
5. What it cannot replace
The model has neither your production data nor your real rules. Whether discounts are mutually exclusive, whether an employee price can combine with a coupon, and how cross-store orders are apportioned — if these are not spelled out, any “reasonable-looking” suggestion may be wrong. It also will not run your environment automatically: concurrency, stale cached values, duplicate message delivery, and time-zone configuration all rely on tests and observation.
So conclusions should be graded: high-confidence local issues can be fixed directly and covered with tests; suggestions that touch business priority should first be checked against the rules; inferences about files it has not seen are only leads, not conclusions.
6. What kind of tests catch silent errors
For composition defects, use a decision table rather than scattered examples. Rows are input combinations (no discount, coupon only, spend-threshold only, both together, coupon amount greater than the amount due, spend-threshold exactly equal to the threshold); columns are the expected amount paid, the discount breakdown, and the rounding result. Assert on the amount and the reason, and avoid asserting only “greater than 0.”
For dates, inject a fixed clock for “month-end, leap year, cross-time-zone midnight” and do not depend on the day the test runs. Across modules, use contract tests: the producer’s sample and the consumer’s parsing must use the same sample, so that changing a field fails both sides together.
For amount calculations, prefer integer cents and fix the rounding point. Silent errors often come from binary floating point and the order of “divide then multiply,” not from syntax.
7. Choosing between basic and enhanced capability
For everyday tasks — explaining code, listing boundaries, checking a small implementation — a basic conversation is usually enough. Whether a membership or higher quota is worthwhile depends on how you review, not on the model’s name.
If the work is occasionally asking about a few functions, the benefit of an enhanced quota is limited. If you need to load multiple files at once, keep a long context, and repeatedly cross-check rules and tests, then context length, the accessible repository scope, and stable tool calls will clearly affect whether cross-file problems can be found. Paying for “being able to see all the relevant code” is more reasonable than paying for “smoother answers.”
You do not need to enable a paid tier for every scenario: first run the same defect sample as a comparison. If the basic capability already points out the stacking order and the missing tests, there is no need to upgrade; only when the material is fully provided yet detection still fails because the context is truncated or the relevant modules cannot be covered should you consider the enhanced tier. Billing and quotas follow the service’s documentation at the time; do not treat a demo’s effect as a capability guarantee.
If a team already uses cloud-based code hosting, continuous integration, and logging services, a more robust approach is to embed model review into the pre-merge check: submit a rule summary, the diff files, and the failure samples together, and require conclusions to land as new assertions. General-purpose code hosting, pipelines, and log alerting on a platform such as Baidu AI Cloud can support “traceable changes and replayable failures,” but the key to finding silent defects is still whether the rules and samples are complete, not outsourcing the conclusion to the model.
8. An executable review workflow
- Write the invariants and the priority of discounts, dates, and fields in three sentences.
- Collect only the truly relevant modules and tests, avoiding unrelated code that dilutes attention.
- Have the model list input combinations, suspicious branches, and points that conflict with the rules, and require it to flag points it “cannot judge because files are unseen.”
- The developer removes false positives and turns the rest into tests; fix the implementation only after a test fails.
- Keep the samples and conclusions at merge time so the next rule change can be rechecked.
Running only shows the current conditions passed. LLMs are good at surfacing hidden assumptions, and, given enough material, at spotting inconsistencies across lines and across files; they cannot invent business rules, nor replace composition tests. Provide the rules, the relevant code, and the failure samples in full, then pin the conclusions down with tests, and silent miscalculation turns from “relying on the human eye and luck” into a repeatable check.
