Teaching AI to Say "I'm Not Sure": Engineering Practices for Trustworthy Outputs
Large language models often present uncertain results with unwarranted confidence, leading to silent defects that require costly manual review. This article outlines a three-level framework for building more trustworthy AI outputs—explicit uncertainty expression, self-verification, and traceable results—and provides concrete engineering practices such as structured prompt templates, secondary review, executable validation, and data-driven miss-rate measurement. Teams can apply these methods to reduce hidden errors and integrate AI outputs into production more safely.
The Problem: Confident Tone vs. Correct Results
When large models generate code, analyze data, or draft reports, their tone is usually assertive. When results contain logical errors or omissions, the model rarely flags them proactively. Developers are forced to go through every line to spot issues, which significantly offsets the efficiency gains from automation.
This can be characterized as a “missed report”: the output is defective, but no declaration is made. The higher the miss rate, the more manual review is required, and the harder it becomes to use results directly in a production pipeline. Solving the missed-report problem requires work in four areas: prompt design, output structure, verification mechanisms, and evaluation of effectiveness.
Three Levels of Trustworthy Outputs
Trustworthy outputs can be broken down into three progressive levels.
- Uncertainty expression: Each key conclusion is appended with a confidence level and an explanation of the insufficiency of evidence.
- Self-verification: After generation, the output is checked against requirements, constraints, and boundary conditions, with the process recorded.
- Traceability: Conclusions include assumptions, source of evidence, and parts that remain unverified, so others can review independently.
The three levels answer different questions. The first addresses whether the model discloses uncertainty; the second, whether the check was thorough; the third, whether the result can be independently verified. If any level is missing, the trustworthiness has a gap.
Engineering Practices
1. Enforce Structured Output in the Prompt
Using a system prompt to require a fixed output structure improves information completeness. Example:
You are a rigorous code review assistant. After completing the task, output in the following structure:1. Implementation result2. Assumptions: list all assumptions you made3. Unverified items: list anything you could not confirm as correct, with reasons4. Confidence: high / medium / low, with a justificationIf anything is uncertain, state it explicitly. Do not use a confident tone for uncertain parts.
The fixed structure forces the model to explicitly list “Unverified items.” Without such a section, the model tends to omit uncertain parts. The assumptions column is equally important, because many defects come from unstated default assumptions about requirements.
2. Perform a Second Review After Generation
Having another model or a separate independent call review the artifact can catch some omissions. The review prompt should focus only on finding defects, without including the original author’s explanation, to reduce confirmation bias.
The review output itself also needs verification. The reviewer may also miss things, so its comments should be treated as leads to verify, not as final conclusions.
3. Use Executable Validation as a Safety Net
The model’s self-report cannot replace validation. For code outputs, use tests, type checking, and static analysis to confirm actual behavior. The example below runs the project test suite in an isolated directory and uses the process return code as the verdict:
import subprocessfrom pathlib import Pathdef verify_generated_code(workdir: Path, test_cmd: list[str], timeout: int = 60) -> bool:"""Run the test command in the specified directory and return whether all tests pass.Note: generated code must be executed in a sandbox or container to avoid affecting the host environment."""result = subprocess.run(test_cmd,cwd=workdir,capture_output=True,text=True,timeout=timeout,)if result.returncode != 0:print(result.stdout[-2000:])return result.returncode == 0
This function only checks whether tests passed; it does not parse the model’s explanation. Even if the model claims “no problem,” a failing test gives a negative verdict. Before execution, limit file system, network, and resource permissions, following the principle of least privilege.
4. Route Based on Uncertainty
When the model marks confidence as low, or the “Unverified items” section is not empty, the pipeline should automatically route the result to human review. This turns uncertainty from a textual hint into an executable routing condition, reducing reliance on model self-awareness.
Measuring Trustworthiness with Data
Subjective impressions are not enough to judge model trustworthiness. Use a labeled sample set to calculate the miss rate:
Miss rate = (number of samples with defects that were not declared as uncertain) / (number of samples with actual defects)
def miss_rate(records: list[dict]) -> float:"""Each record contains has_defect (true if a defect exists) and declared (whether the model declared uncertainty)."""defective = [r for r in records if r["has_defect"]]if not defective:return 0.0missed = [r for r in defective if not r["declared"]]return len(missed) / len(defective)
Calculate the miss rate separately for each task type, and compare it with prompt or model version changes. If you only look at the overall average, problems in high-risk tasks may be hidden. Also track the false positive rate—cases where the model declares uncertainty even though there is no defect—because too many false positives increase ineffective review load. The two metrics must be weighed together.
Notes for Deployment
- The model’s self-reported confidence is usually not a calibrated probability. Use a validation set to check its relationship with actual correctness.
- In high-risk scenarios (finance, permissions, medical, safety), require human review by default and do not rely on model self-report alone.
- Record the prompt version, model version, and evaluation results for each generation to support issue tracing and performance comparisons.
- Execute generated code in an isolated environment first, then consider connecting to real data or services.
Checklist
- Does the output structure include assumptions, unverified items, and confidence level?
- Do key conclusions have executable verification methods?
- Are results with low confidence or unverified items routed into human review?
- Do you regularly compute miss rate and false positive rate on labeled samples, and compare across history versions?
