> ## Documentation Index
> Fetch the complete documentation index at: https://docs.monostate.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Hallucinations & Limitations

> Understanding when AI models get things wrong

# 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

<Warning>
  **Fake Methods and Functions**

  Models often invent methods that don't exist but sound like they should.
</Warning>

```python theme={null}
# Model suggests:
df.remove_outliers(threshold=3)

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

### In Documentation

<Warning>
  **Fictional API Endpoints**

  Models create endpoints that follow naming conventions but aren't real.
</Warning>

```javascript theme={null}
// Model suggests:
import { debounce } from "react";

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

### In Configuration

<Warning>
  **Invalid Settings**

  Models suggest config options that seem logical but aren't valid.
</Warning>

```json theme={null}
// Model suggests for package.json:
{
  "type": "module",
  "exports": "./index.js",
  "browser": true  // This isn't a valid option!
}
```

### In Facts and Numbers

<Warning>
  **Made-up Statistics**

  Models generate specific numbers that sound authoritative but are fabricated.
</Warning>

* "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.

<Note>
  **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.
</Note>

### 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:

```python theme={null}
# 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:

| Model             | Context Window   |
| ----------------- | ---------------- |
| GPT-5             | 400,000 tokens   |
| Claude Sonnet 4.5 | 200,000 tokens   |
| Gemini 2.5 Pro    | 1,000,000 tokens |

When context is full, models:

* Forget earlier information
* Mix up details
* Generate based on partial understanding

## How to Spot Hallucinations

<Steps>
  <Step title="Too Perfect">
    If the answer seems too convenient or exactly what you wanted, verify it.
  </Step>

  <Step title="Specific Without Source">
    Very specific claims without references are often made up.
  </Step>

  <Step title="Mixing Concepts">
    Combining features from different libraries or versions.
  </Step>

  <Step title="Confident but Vague">
    Using lots of words without saying anything concrete.
  </Step>
</Steps>

## 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

<CardGroup cols={2}>
  <Card title="Clean Your Data">
    * Remove contradictions
    * Fix incorrect labels
    * Update outdated info
    * Balance categories
  </Card>

  <Card title="Augment Carefully">
    * Use verified sources
    * Synthetic data quality
    * Maintain consistency
    * Preserve real patterns
  </Card>
</CardGroup>

### 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

<Note>
  **Key Principle**: Every model output is a starting point, not a final answer.
</Note>

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

<CardGroup cols={2}>
  <Card title="Hallucinations & Entropy Research" icon="flask" href="https://monostate.com/blog/hallucinations-entropy-llms">
    Our main research article on controlling hallucinations through entropy analysis
  </Card>

  <Card title="Test-Time Hallucination Control" icon="vial" href="https://monostate.com/blog/entropy-refinement-blog">
    Practical techniques for reducing hallucinations at inference time
  </Card>
</CardGroup>

## Next Steps

Now that you understand model limitations:

<CardGroup cols={3}>
  <Card title="Entropy & Uncertainty" href="/foundations/entropy-uncertainty">
    Deep dive into the mathematics
  </Card>

  <Card title="Data Quality" href="/foundations/datasets-and-formats">
    Learn to prepare better training data
  </Card>

  <Card title="Evaluation Metrics" href="/foundations/evaluation-metrics">
    Measure model performance accurately
  </Card>
</CardGroup>
