๐Ÿค– Android AI and Generative AI

Evaluating AI Responses and Reducing Hallucinations

AI features fail differently from normal code: the same input can produce different outputs, and wrong answers look confident. You can't unit-test your way to quality alone. You need evaluation datasets, layered checks and techniques that reduce hallucinations in the first place.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 3 min read ๐ŸŽฏ Advanced
On this page
  1. Reducing hallucinations by design
  2. Build a golden evaluation set
  3. Automated checks, from cheap to expensive
  4. Regression testing
  5. Learning from production
  6. Applying it
  7. Frequently asked questions
  8. Conclusion

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

Layers that reduce and contain hallucinations Five layers: ground answers in retrieved data; constrain the task and output with schemas and low temperature; allow and encourage I don't know; verify outputs with validation and citations; and design the UI so users can check sources and report problems. GroundRAG, tools,real data Constrainnarrow task,schema, low temp Allow "I don'tknow"explicit refusal Verifyvalidation,citation checks ContainUX: sources,edit, report
Each layer catches what the previous one missed. No single technique is enough.
  • 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.

EvalCase.ktKotlin
@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

CheckCatchesCost
Schema/format validationBroken JSON, missing fieldsFree
Rule checks (contains/forbids, length, valid IDs)Obvious errors, policy violationsFree
Citation verificationInvented sourcesCheap
LLM-as-judge (rubric scoring)Faithfulness, helpfulness, toneModel calls; needs calibration
Human review of samplesSubtle errors, real-world qualityTime
LLM-as-judge needs care

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

  1. Run the evaluation set whenever you change the prompt, model, retrieval or temperature.
  2. Compare pass rates per category against the previous version.
  3. Block releases on significant drops, and review failures manually.
  4. 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.

See all our apps โ†’

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.

Share: LinkedIn X / Twitter WhatsApp