On this page
A hallucination is output that's fluent but unsupported or false: a made-up refund policy, an invented API method, a wrong date. Models can't be made hallucination-free, but systems can make hallucinations rarer, easier to detect, and less harmful.
Reducing hallucinations by design
- Ground answers in retrieved documents or tool results, not model memory. See RAG and Function Calling.
- Constrain: narrow tasks, schemas, low temperature for factual work.
- Permit uncertainty: instruct "if the answer isn't in the context, say you don't know", and reward it in evaluation.
- Verify: validate structured fields, check that citations exist, cross-check numbers against your data.
- Contain: show sources, let users edit, and avoid AI-only decisions in high-stakes domains.
Build a golden evaluation set
Collect 50โ200 realistic inputs (with consent and anonymisation) covering common cases, edge cases, other languages, adversarial inputs, and questions that should be refused. For each, note what a good answer must contain or avoid.
@Serializable
data class EvalCase(
val id: String,
val input: String,
val mustContain: List<String> = emptyList(),
val mustNotContain: List<String> = emptyList(),
val shouldRefuse: Boolean = false,
val maxWords: Int = 150,
)
data class EvalOutcome(val id: String, val passed: Boolean, val reasons: List<String>)
fun check(case: EvalCase, output: String, refused: Boolean): EvalOutcome {
val reasons = buildList {
if (case.shouldRefuse != refused) add(if (case.shouldRefuse) "should have refused" else "refused wrongly")
case.mustContain.filterNot { output.contains(it, ignoreCase = true) }.forEach { add("missing: $it") }
case.mustNotContain.filter { output.contains(it, ignoreCase = true) }.forEach { add("forbidden: $it") }
if (output.split(Regex("\\s+")).size > case.maxWords) add("too long")
}
return EvalOutcome(case.id, reasons.isEmpty(), reasons)
}Automated checks, from cheap to expensive
| Check | Catches | Cost |
|---|---|---|
| Schema/format validation | Broken JSON, missing fields | Free |
| Rule checks (contains/forbids, length, valid IDs) | Obvious errors, policy violations | Free |
| Citation verification | Invented sources | Cheap |
| LLM-as-judge (rubric scoring) | Faithfulness, helpfulness, tone | Model calls; needs calibration |
| Human review of samples | Subtle errors, real-world quality | Time |
Judges have their own biases and errors. Use clear rubrics, check them against human ratings on a sample, and never treat their scores as ground truth.
Regression testing
- Run the evaluation set whenever you change the prompt, model, retrieval or temperature.
- Compare pass rates per category against the previous version.
- Block releases on significant drops, and review failures manually.
- Record prompt and model versions with results.
Learning from production
- Add thumbs up/down and "report" on AI outputs, and capture the reason.
- Track acceptance, edit and regeneration rates for suggestions.
- Sample and review conversations (with consent and privacy safeguards), then add failures to the golden set.
Applying it
Help assistant
Golden questions per help article, plus "not covered" questions that must be refused, with citation checks.
Extraction
Field-level accuracy against labelled receipts, and schema validation on every response.
Writing suggestions
Acceptance rate, plus checks that names and numbers are preserved.
Frequently asked questions
Can I eliminate hallucinations?
No. You can reduce and contain them. Design features so occasional errors are visible, correctable and low-impact.
How often should I run evaluations?
On every prompt, model or retrieval change, and periodically, since providers update models.
Is temperature 0 deterministic?
Not always across calls or model versions. Treat evaluation results statistically, and run each case more than once for critical features.
Conclusion
Quality AI features combine prevention (grounding, constraints, permission to say "I don't know"), verification (validation, citation checks) and evaluation (golden datasets, regression runs, production feedback). Treat quality as an ongoing process, not a launch checklist.
Next step: explore the AI tools that help you build, starting with AI Coding Assistants for Android Developers.
Official references
๐ฑ Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
Ready to build real Android applications?
Every AI feature still runs inside an Android app that has to be fast, reliable and well structured. Strengthen the Kotlin, Jetpack Compose and architecture skills that AI integrations depend on, then apply these AI concepts with confidence.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.