Prompt Engineering & LLM Optimization for Developers · レッスン

ハルシネーションの検出と軽減

ハルシネーションとは、確信に満ちているものの誤ったLLMの出力です。発生する理由、検出方法、本番環境で減らす具体的な技術を学びます。

レッスン 4/413 ステップ

「ハルシネーションの検出と軽減」はCoddyKit上の無料Prompt Engineering & LLM Optimization for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはPrompt Engineering & LLM Optimization for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Prompt Engineering & LLM Optimization for Developersコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

無料で開始

AI チューターと学ぶ Prompt Engineering & LLM Optimization for Developers — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
12
レッスン
48

よくある質問

「ハルシネーションの検出と軽減」レッスンは無料ですか?

はい。「ハルシネーションの検出と軽減」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Prompt Engineering & LLM Optimization for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Prompt Engineering & LLM Optimization for Developersコースには全4レッスンが含まれています。

「ハルシネーションの検出と軽減」で何を学びますか?

ハルシネーションとは、確信に満ちているものの誤ったLLMの出力です。発生する理由、検出方法、本番環境で減らす具体的な技術を学びます。 ブラウザで直接実行するハンズオンコードでPrompt Engineering & LLM Optimization for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Prompt Engineering & LLM Optimization for Developersを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのPrompt Engineering & LLM Optimization for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「ハルシネーションの検出と軽減」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このPrompt Engineering & LLM Optimization for Developersレッスンでコードを書いて実行できますか?

はい。すべてのPrompt Engineering & LLM Optimization for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. LLMの評価指標とベンチマーク
  2. Human-in-the-Loopフィードバックシステム
  3. プロンプトインジェクションとセキュリティのベストプラクティス
  4. ハルシネーションの検出と軽減
← Prompt Engineering & LLM Optimization for Developersに戻る