Detectando e Mitigando Alucinações
Alucinações são saídas de LLM confiantes, mas falsas. Aprenda por que acontecem, como detectá-las e técnicas concretas para reduzi-las em produção.
Detectando e Mitigando Alucinações é uma aula grátis de Prompt Engineering & LLM Optimization for Developers no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Prompt Engineering & LLM Optimization for Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Prompt Engineering & LLM Optimization for Developers inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
What is a Hallucination?
A hallucination is when an LLM produces text that is fluent and confident but factually wrong or unsupported by any source.
Because the output looks authoritative, hallucinations are dangerous in user-facing apps.
Why They Happen
LLMs predict the most likely next token, not the truth. With no grounding, they fill gaps with plausible-sounding inventions.
- Missing knowledge in training data
- Ambiguous or leading prompts
- Pressure to always answer
Types of Hallucination
Two broad categories:
- Factual: wrong dates, fake citations, invented APIs
- Faithfulness: answer contradicts the provided context (common in RAG)
Grounding with Context
The strongest defense is grounding: give the model trusted source text and instruct it to answer only from that text.
Answer ONLY using the context below.
If the answer is not in the context, say "I do not know".
Context:
{retrieved_docs}Forcing Citations
Ask the model to cite which passage supports each claim. Unsupported sentences become easy to spot and verify.
For each sentence, add a [doc_id] citation.
Do not make claims you cannot cite.Lowering Temperature
Higher temperature increases creativity — and invention. For factual tasks, set a low temperature so the model stays close to high-probability, well-grounded tokens.
const res = await client.chat.completions.create({
model: "gpt-4o-mini",
temperature: 0,
messages
});Self-Consistency Checks
Generate the answer several times. If the model gives different facts each run, the claim is likely a hallucination. Agreement is a weak but useful signal of reliability.
LLM-as-a-Judge Verification
Use a second model call to check whether the answer is supported by the context. The judge returns a faithfulness verdict you can act on.
Does the ANSWER follow only from the CONTEXT?
Reply: SUPPORTED, PARTIAL, or UNSUPPORTED.Programmatic Validation
When outputs are structured, validate them. A cited URL should resolve, a quoted number should match the source, a JSON field should match a schema.
function validateCitation(cit, docs) {
return docs.some(d => d.id === cit.doc_id);
}Letting the Model Abstain
Give the model permission to say I do not know. Removing the pressure to always answer measurably reduces fabricated content.
Human Review for High Stakes
For medical, legal, or financial outputs, route low-confidence or uncited answers to a human before showing them to users. Automation plus oversight beats either alone.
Quick Check
Test your understanding.
Recap
You learned to fight hallucinations: ground answers in trusted context, force citations, lower temperature, use self-consistency and LLM-as-a-judge checks, validate outputs programmatically, allow abstention, and add human review for high-stakes cases.
Perguntas Frequentes
A aula “Detectando e Mitigando Alucinações” é grátis?
Sim — o texto completo de “Detectando e Mitigando Alucinações” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Prompt Engineering & LLM Optimization for Developers, atualize para CoddyKit PRO. O curso de Prompt Engineering & LLM Optimization for Developers inclui 4 aulas no total.
O que vou aprender em “Detectando e Mitigando Alucinações”?
Alucinações são saídas de LLM confiantes, mas falsas. Aprenda por que acontecem, como detectá-las e técnicas concretas para reduzi-las em produção. Você pratica Prompt Engineering & LLM Optimization for Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Prompt Engineering & LLM Optimization for Developers?
Nenhuma experiência prévia é necessária. Prompt Engineering & LLM Optimization for Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Detectando e Mitigando Alucinações”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Prompt Engineering & LLM Optimization for Developers?
Sim. Cada aula de Prompt Engineering & LLM Optimization for Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Métricas e referências de avaliação de LLMs
- Sistemas de feedback com participação humana
- Injeção de prompts e boas práticas de segurança
- Detectando e Mitigando Alucinações