Skip to main content

When Models Make Things Up

AI models are powerful, but they’re not perfect. Understanding their limitations helps you train better models and work with them more effectively.

What Are Hallucinations?

Hallucination is when an AI model confidently generates information that seems plausible but is actually incorrect. It’s like when someone tries to bluff their way through a conversation about a topic they don’t really know.

Why Models Hallucinate

Remember how models predict the next most likely token? Sometimes those predictions create fiction that sounds like fact. Think of models like extremely sophisticated autocomplete:
  • Phone autocomplete: “The weather is…” → “sunny”
  • AI model: “The function to reverse a list is…” → makes up something plausible
When a model doesn’t know something, it doesn’t say “I don’t know.” Instead, it generates what seems most likely based on patterns it has learned.

Common Hallucination Types

In Code Generation

Fake Methods and FunctionsModels often invent methods that don’t exist but sound like they should.
# Model suggests:
df.remove_outliers(threshold=3)

# Reality: pandas DataFrames don't have this method
# You need to implement outlier removal yourself

In Documentation

Fictional API EndpointsModels create endpoints that follow naming conventions but aren’t real.
// Model suggests:
import { debounce } from "react";

// Reality: React doesn't export debounce
// You need lodash or write your own

In Configuration

Invalid SettingsModels suggest config options that seem logical but aren’t valid.
// Model suggests for package.json:
{
  "type": "module",
  "exports": "./index.js",
  "browser": true  // This isn't a valid option!
}

In Facts and Numbers

Made-up StatisticsModels generate specific numbers that sound authoritative but are fabricated.
  • “BERT has exactly 340 million parameters” (it’s actually 110M or 340M depending on version)
  • “PyTorch was released in 2014” (actually 2016)
  • “The optimal learning rate is always 2e-5” (depends on many factors)

Knowledge Cutoff Issues

Models are trained on data up to a specific date. After that date, they know nothing.
Example Knowledge Cutoffs:
  • GPT-5: Latest from OpenAI
  • Claude Sonnet 4.5: Latest from Anthropic
  • Gemini 2.5 Pro: Latest from Google
Always check when asking about recent developments.

What This Means

If you ask about:
  • Libraries released after the cutoff → Wrong or no information
  • Recent best practices → Outdated advice
  • Current versions → Old version numbers
  • New features → Complete fabrication

Other Model Limitations

Mathematical Weakness

Models struggle with precise calculations:
# Don't trust models for:
- Complex arithmetic
- Counting characters in strings
- Generating truly random numbers
- Precise floating-point operations

Logical Reasoning

Models can fail at simple logic:
  • “All birds can fly. Penguins are birds. Can penguins fly?” → May say yes
  • Counting problems: “How many ‘r’s in ‘strawberry’?” → Often wrong
  • Spatial reasoning: “If A is north of B, and B is north of C…” → Gets confused

Consistency Issues

Models may contradict themselves:
  • Give different answers to the same question
  • Change their “opinion” based on how you phrase things
  • Agree with you even when you’re wrong

Context Limitations

Models have finite context windows:
ModelContext Window
GPT-5400,000 tokens
Claude Sonnet 4.5200,000 tokens
Gemini 2.5 Pro1,000,000 tokens
When context is full, models:
  • Forget earlier information
  • Mix up details
  • Generate based on partial understanding

How to Spot Hallucinations

1

Too Perfect

If the answer seems too convenient or exactly what you wanted, verify it.
2

Specific Without Source

Very specific claims without references are often made up.
3

Mixing Concepts

Combining features from different libraries or versions.
4

Confident but Vague

Using lots of words without saying anything concrete.

Verification Strategies

For Code

  1. IDE/Compiler Feedback
    • Red underlines indicate problems
    • Import errors show fake modules
    • Type errors reveal incorrect APIs
  2. Documentation Check
    • Always verify in official docs
    • Check version compatibility
    • Look up method signatures
  3. Run and Test
    • Execute the code
    • Write unit tests
    • Use debugging tools

For Information

  1. Cross-Reference
    • Check multiple sources
    • Verify dates and numbers
    • Confirm with official documentation
  2. Ask for Sources
    • Request specific documentation links
    • Ask which version supports a feature
    • Get example code from real projects
  3. Test Claims
    • Verify mathematical calculations
    • Check logical conclusions
    • Run benchmarks yourself

Working Around Limitations

Prompt Engineering

Make your prompts more specific:
# Instead of:
"Write a function to process data"

# Try:
"Write a Python function using pandas 2.0 to filter rows where column 'age' > 18"

Provide Context

Give the model accurate information:
# Include relevant details:
"Using React 18.2 with TypeScript 5.0, create a component..."

# Provide examples:
"Following this pattern from our codebase: [example]"

Iterative Refinement

Work with the model iteratively:
  1. Get initial suggestion
  2. Test and identify issues
  3. Feed errors back to model
  4. Refine until correct

Use Model Strengths

Models are good at:
  • Pattern recognition
  • Code structure
  • Explaining concepts
  • Generating boilerplate
  • Suggesting approaches
Models are bad at:
  • Latest information
  • Precise calculations
  • Guaranteeing correctness
  • Domain-specific details
  • Real-time data

Hallucinations in Training

When training your own models, hallucinations can occur from:

Training Data Issues

  • Incorrect labels: Model learns wrong patterns
  • Outdated information: Old documentation in training set
  • Contradictions: Conflicting examples confuse the model
  • Sparse data: Model guesses for rare cases

Overfitting

Model memorizes training data instead of learning patterns:
  • Generates training examples verbatim
  • Can’t generalize to new inputs
  • Mixes memorized fragments incorrectly

Underfitting

Model hasn’t learned enough:
  • Makes random guesses
  • Generates generic responses
  • Misses important patterns

Reducing Hallucinations in Your Models

Data Quality

Clean Your Data

  • Remove contradictions
  • Fix incorrect labels
  • Update outdated info
  • Balance categories

Augment Carefully

  • Use verified sources
  • Synthetic data quality
  • Maintain consistency
  • Preserve real patterns

Training Strategies

  1. Validation Sets
    • Hold out test data
    • Check for hallucinations
    • Measure accuracy carefully
  2. Regularization
    • Prevent overfitting
    • Use dropout
    • Early stopping
    • Weight decay
  3. Temperature Control
    • Lower temperature = more conservative
    • Higher temperature = more creative (more hallucinations)
    • Find the right balance

Post-Training

  • Human evaluation: Have experts check outputs
  • Automated testing: Build test suites
  • Confidence scores: Add uncertainty estimates
  • Fallback options: “I don’t know” responses

The Verification Mindset

Key Principle: Every model output is a starting point, not a final answer.
Developing a verification mindset means:
  • Question confident assertions
  • Test generated code
  • Verify claimed facts
  • Cross-reference sources
  • Understand before using
This isn’t extra work - it’s making you better at your craft by forcing you to understand what the model produces.

Living with Limitations

Models are tools, not oracles. They’re incredibly useful despite their flaws:
  • Speed: Generate solutions in seconds
  • Breadth: Know about many topics
  • Creativity: Suggest approaches you hadn’t considered
  • Tirelessness: Available 24/7
The key is understanding when to trust and when to verify.

Learn More from Our Research

Next Steps

Now that you understand model limitations: