← Back to Blog

Why Your LLM Gets It Wrong: The Hidden Cost of Missing Context

AILLMContext EngineeringBest Practices

I was chatting with airline staff during a recent Trans-Pacific flight, and we got on the topic of the “Austria vs. Australia” confusion.

Apparently, it happens often enough that there’s a giant counter specifically for travelers who have booked the wrong country. Imagine the confusion: you’re expecting kangaroos, you get schnitzel. This creates massive frustration and, at the end of the day, requires another long-haul flight to get you where you actually wanted to go.

As engineers, we deal with this daily. And nowhere is it more apparent than when working with Large Language Models.

The Stateless Reality

A raw LLM session is stateless. It doesn’t know:

  • Your architecture
  • Your variable naming conventions
  • That specific edge case you fixed last week
  • What “the thing” refers to in your codebase

It starts every prompt with a blank slate. Just like a booking agent who only has “I want to go to Austria” to work with.

The Cost of Ambiguity

When you ask an LLM to “fix the bug in the payment form,” you’re essentially saying “take me there” and hoping it guesses right. Sometimes it does. Often it doesn’t.

The model might:

  • Assume you’re using React when you’re using Vue
  • Generate TypeScript when your project is JavaScript
  • Fix a different bug than the one you meant
  • Use patterns that conflict with your codebase style

Each wrong guess costs time. And like a flight to the wrong continent, the further you go before realizing the mistake, the more expensive the correction.

Context is the Map

The solution isn’t smarter models (though those help). It’s better context.

What Good Context Looks Like

Bad prompt:

Fix the login bug

Better prompt:

In our React 18 TypeScript codebase, the login form in `src/components/LoginForm.tsx` throws a “Cannot read property ‘email’ of undefined” error when the user submits with an empty form. We use React Hook Form for validation. Here’s the relevant code: [paste code]

The second prompt is longer, but it eliminates guesswork. The model knows:

  • The framework (React 18)
  • The language (TypeScript)
  • The exact file
  • The exact error
  • The validation library
  • The actual code

Practical Context Strategies

1. Include the File Tree (Selectively)

Don’t dump your entire repo structure, but give the model a sense of where things live:

``` src/ components/ LoginForm.tsx <- we’re working here AuthProvider.tsx hooks/ useAuth.ts types/ user.ts ```

2. Paste Relevant Types

If you’re working with TypeScript, include the types. The model will use them:

```typescript interface User { id: string; email: string; role: ‘admin’ | ‘user’; } ```

3. Explain Your Conventions

A quick note about style saves regeneration:

“We use early returns, avoid nested ternaries, and prefer explicit types over inference.”

4. Show Examples

If you want code in a specific style, show the model what that looks like:

“Here’s how we typically write API handlers in this codebase: [example]“

The RAG Advantage

This is why RAG (Retrieval-Augmented Generation) systems are so powerful. Instead of relying on what the model “knows,” you inject the specific context it needs at query time.

When a developer asks “how do we handle authentication?”, a RAG system can pull:

  • Relevant docs
  • Existing auth code
  • Recent PRs touching auth

The model isn’t guessing. It’s working with actual source material.

The Meta-Lesson

Next time you get a wrong result from an LLM, ask yourself: Did I give it a map to Australia, or did I just say “take me there” and let it guess?

The model isn’t dumb. It’s working with what you gave it. And if you give it “Austria” levels of context, don’t be surprised when you end up eating schnitzel instead of watching kangaroos.

Key Takeaways

  1. LLMs are stateless — they know nothing about your project unless you tell them
  2. Ambiguity is expensive — vague prompts lead to wrong outputs
  3. Context is cheap — a few extra lines of context saves regeneration cycles
  4. Be specific — file names, line numbers, error messages, types
  5. Show, don’t tell — examples are more effective than descriptions

The difference between frustrating AI interactions and productive ones usually isn’t the model — it’s the context you provide.