Mitigating LLM Hallucination: Handling Contradictory Information and Stability Testing

    This article examines how large language models and AI coding tools fail when they encounter contradictory business information, such as conflicting pricing pages and announcements. It explains the root causes of "selective contradiction ignoring," outlines the three pillars of trustworthy question answering—conflict detection, confidence calibration, and output stability—and presents a reproducible multi-round evaluation method with structured JSONL logging. Finally, it details an engineering governance approach combining prompt constraints, retrieval augmentation, external validation, and monitoring to move AI coding tools from "looking correct" to "provably correct."

    1. Background: From “Wish-Based Coding” to a Stability Test

    The idea of “wish-based coding, one click to reality” has recently gained traction: developers describe their intent in natural language, and an AI coding tool generates runnable code. However, once these tools are connected to real business knowledge—such as billing rules or announcement terms—a problem emerges. When a model faces conflicting information on a page, it often produces a confident answer without any verification. In engineering terms, this is called “selective contradiction ignoring,” a highly concealed form of hallucination: the answer looks complete and self-assured, but it has not undergone any consistency check.

    One developer’s hands-on test is representative. Using two model tiers of an AI coding tool, he ran the same question—“the pricing page directly contradicts the announcement”—30 times per tier, across two supply channels (an official channel and a third-party hosting channel, with matching model fingerprints). The results: the higher-tier model gave an incorrect conclusion in roughly 60% of runs, while the lower-tier model was wrong only once in 30 runs; a single attempt on the web interface showed no anomaly. The conclusion seemed optimistic, but two casual retries that evening were both wrong, and the logs (JSONL) showed the same flaw—ignoring an obvious contradiction and directly outputting an unverified answer.

    This reveals a key fact: a “pass” from a single run or a small sample does not prove stability. LLM output is stochastic; temperature settings, context organization, and subtle differences in system prompts can all shift the result distribution. To evaluate whether a model is “reliable,” you must introduce a statistical perspective and a reproducible evaluation framework.

    2. The Core Problem: A Consistency Reasoning Defect Under Contradictory Information

    Abstracting the phenomenon yields three technical points.

    First, information conflict detection. When two authoritative sources (a pricing page and an announcement) give inconsistent conclusions, a qualified system should identify the conflict first rather than picking one to believe. This requires the model to reason in the order of “align facts first, then answer.”

    Second, confidence calibration. A model should not express high confidence without verification. The ideal behavior is to explicitly state uncertainty and trigger a secondary check.

    Third, output stability. Under multi-round sampling, the same input should keep the conclusion consistent, or at least keep the error rate controllable and predictable.

    Together these three form the baseline for “trustworthy question answering.” Missing any one of them, an AI coding tool in a business-knowledge scenario can deliver an inconsistent “sometimes works, sometimes doesn’t” experience, making it hard for developers to build trust.

    3. A Reproducible Multi-Round Evaluation Method

    To quantify stability, use the following process.

    1. Fix the evaluation set: prepare a batch of samples with inherent contradictions (e.g., pricing page vs. announcement, documentation vs. API response), and label each sample with the “correct behavior” (identify the conflict and request clarification) and the “incorrect behavior” (directly give a single answer).
    2. Multi-round sampling: run each sample for N rounds (N≥30) and record the output of each round.
    3. Multi-channel comparison: cover both the official channel and third-party hosting channels, and verify that model fingerprints match to rule out “same name, different model” interference.
    4. Structured logging: write each round’s input, output, latency, and token usage into JSONL for replay and root-cause analysis.
    5. Metric calculation: compute error rate, conflict detection rate, and confidence calibration error (e.g., the proportion of outputs marked “certain” that are actually wrong).

    Illustrative evaluation pseudocode:

    1. import json, collections
    2. def run_eval(model_client, samples, n=30):
    3. stats = collections.defaultdict(lambda: {"total":0, "error":0, "conflict_caught":0})
    4. with open("eval.jsonl", "w", encoding="utf-8") as f:
    5. for s in samples:
    6. for i in range(n):
    7. out = model_client.generate(s["prompt"])
    8. caught = detect_conflict(out) # whether the contradiction is explicitly pointed out
    9. err = 0 if caught else grade(out, s["gold"])
    10. rec = {"sample": s["id"], "round": i, "output": out,
    11. "conflict_caught": caught, "error": err}
    12. f.write(json.dumps(rec, ensure_ascii=False) + "\n")
    13. st = stats[s["id"]]
    14. st["total"] += 1; st["error"] += err; st["conflict_caught"] += caught
    15. return {k: {"error_rate": v["error"]/v["total"],
    16. "conflict_rate": v["conflict_caught"]/v["total"]} for k,v in stats.items()}

    4. Log Analysis: Locating the Root Cause of “Selective Ignoring”

    Once you have the JSONL, focus on three signals.

    First, whether the conflict is mentioned. If the output never cites either the announcement or the pricing page, the model did not perform a cross-comparison. Second, the certainty of the wording. Strong assertions such as “certainly / definitely / it is exactly” without evidence indicate miscalibrated confidence. Third, context truncation. Check whether the input tokens exceed the limit, causing the announcement content to be dropped—a common engineering-side trigger.

    After attribution, fix the issue at three layers: data, prompt, and process. At the data layer, add contradictory samples for fine-tuning or retrieval augmentation; at the prompt layer, enforce “list conflicts before answering”; at the process layer, introduce external rule validation to programmatically compare key fields (e.g., price, effective time).

    5. Engineering Governance Approach

    For production environments, the recommended combination is “prompt constraints + retrieval augmentation + external validation + monitoring and alerting.”

    • Prompt constraints: in the system prompt, explicitly state “if sources conflict, you must output a conflict explanation and request clarification; arbitrary assumptions are forbidden.”
    • Retrieval augmentation: slice the pricing page and the announcement into separate documents with source and timestamp metadata so the model can cite them.
    • External validation: use a rule engine to compare structured fields; if they are inconsistent, block the output and fall back to a human.
    • Monitoring and alerting: connect error rate and conflict detection rate to logging services and monitoring alerts, with thresholds that trigger a review.

    Illustrative system prompt:

    1. You are a rigorous knowledge question-answering assistant. Before answering, you must:
    2. 1) list all cited sources and their key conclusions;
    3. 2) if conflicts exist among sources, explicitly point out the conflict points and do not adopt one side unilaterally;
    4. 3) when you cannot confirm, output "manual verification required" and explain what information is missing.

    6. Conclusion and Recommendations

    The vision of “wish-based coding” is appealing, but real-world adoption requires crossing the stability threshold. Facing contradictory information, a trustworthy system must have three capabilities: conflict detection, confidence calibration, and output consistency. Developers should abandon the illusion that “one success means it meets the bar” and shift to engineering practices that combine multi-round statistical evaluation, structured logging, and external validation. Only by upgrading “looks correct” to “provably correct” can AI coding tools truly enter core business scenarios.