DEV Community

Tyler Biffle
Tyler Biffle

Posted on

I Stopped "Prompting" GPT-5. This 45-Line Context Engine Fixed My Hallucinations.


Yesterday at 3:00 AM, I was ready to throw my M4 Mac Mini out the window.

I was locked in a recursive argument with GPT-o1. I needed it to refactor a simple authentication middleware, but it kept hallucinating a helper function called validateUserToken().

The problem? That function didn't exist. It had never existed.

I wrote a 1,200-word prompt. I explained my directory structure. I copy-pasted the utils.py file. I pleaded. I coerced. I used "Chain of Thought" prompting.

It didn't matter. The AI was looking at my codebase through a keyhole, trying to describe a ballroom it couldn't see.

That’s when I realized: Prompt Engineering is a cope. We are trying to use better adjectives to fix a data starvation problem.If your AI is hallucinating, it’s not because you aren't "expert" enough at prompting; it’s because your AI has the "Memory of a Goldfish."

I deleted the mega-prompt. I wrote 45 lines of Python. And suddenly, the hallucinations stopped.

The Analogy: The Blind Architect vs. The Blueprints
Imagine you’ve hired the world’s most brilliant architect to renovate your kitchen. This architect is a genius, but there’s a catch: they are blindfolded.

To help them, you stand in the middle of the kitchen and describe the sink. You describe the fridge. You tell them where the load-bearing wall is. You use beautiful, descriptive language.

No matter how good your "Prompting" is, the architect is eventually going to suggest a cabinet that hits the ceiling fan or a drawer that blocks the dishwasher. Why? Because they don't have the Blueprints.

In 2026, most developers are still acting as the "Narrator" for their AI. We are trying to describe the blueprints instead of just handing them over.

Context Engineering is the act of taking off the blindfold.

Why "Prompt Engineering" is Dying in 2026
For two years, we’ve been told that "Prompt Engineering" is the career of the future. We were wrong.

Prompting is a bridge. It was necessary when context windows were small (8k, 32k tokens). But now, with million-token windows and reasoning models like o1 and GPT-5, the bottleneck isn't the instruction—it’s the environment.

When you provide "Sovereign Context," you move from:

The Guessing Game: "Try to write code that fits my style."

The Deterministic Reality: "Write code that implements Interface X found in types.ts."

The Solution: The "Context Engine" Script
Stop copy-pasting. Stop explaining. Use this script to "collate" your project's soul into a single, XML-mapped block that modern LLMs can digest with near-perfect accuracy.

Python

import os

def generate_context_engine(root_dir, exclude_dirs=None, allowed_extensions=None):

"""

Collates project structure and file content into a structured XML map.

Optimized for GPT-o1, GPT-5, and Claude 4 Reasoning Models.

"""

if exclude_dirs is None:

exclude_dirs = {'.git', 'node_modules', 'pycache', 'dist', 'build', '.next', 'env', 'venv'}

if allowed_extensions is None:

allowed_extensions = ('.py', '.js', '.ts', '.tsx', '.html', '.css', '.json', '.yaml', '.md')

context_output = "\n"

1. Map the File Tree first (The 'Vision' Phase)

context_output += " \n"

for root, dirs, files in os.walk(root_dir):

dirs[:] = [d for d in dirs if d not in exclude_dirs]

level = root.replace(root_dir, '').count(os.sep)

indent = ' ' * 4 * (level + 1)

context_output += f"{indent}{os.path.basename(root)}/\n"

sub_indent = ' ' * 4 * (level + 2)

for f in files:

if f.endswith(allowed_extensions):

context_output += f"{sub_indent}{f}\n"

context_output += " \n\n"

2. Extract Source Code (The 'Logic' Phase)

context_output += " \n"

for root, dirs, files in os.walk(root_dir):

dirs[:] = [d for d in dirs if d not in exclude_dirs]

for file in files:

if file.endswith(allowed_extensions):

file_path = os.path.join(root, file)

rel_path = os.path.relpath(file_path, root_dir)

try:

with open(file_path, 'r', encoding='utf-8') as f:

code_content = f.read()

context_output += f" \n"

context_output += f"<![CDATA[\n{code_content}\n]]>\n"

context_output += " \n"

except Exception:

continue

context_output += " \n"

return context_output

Usage: Run this and pipe the output to your LLM

print(generate_context_engine('.'))

Why XML Tags? (The Cognitive Architecture)
You might be wondering: Why and tags? Why not just dump the text?

LLMs trained in 2025 and 2026 are heavily reinforced on web data and documentation. They treat XML/HTML tags as high-priority boundary markers.

When you wrap your code in <![CDATA[ ... ]]>, you are telling the model's attention mechanism: "This is a discrete unit of truth." Without these boundaries, the AI experiences Semantic Bleed. It starts mixing the variables from your User model with the logic in your Product model. The XML tags act as "firewalls" for the AI’s reasoning.

The Death of the "Prompt Engineer"
I’ll be honest with you. I used to pride myself on my "Prompt Engineering" skills. I had a Notion doc full of "System Prompts."

I was wrong. I was building a faster horse when the engine had already been invented. In the age of Agentic AI, your value as a developer isn't in how well you can "talk" to a bot. It’s in how well you can curate the data the bot consumes.

We are moving from "Writer" to "Librarian."

The "Semantic Drift" Warning
If you don't use a Context Engine, you are susceptible to Semantic Drift. This is when your AI slowly diverges from your project’s actual architecture over a long session.

Because you are only feeding it snippets, it starts to "hallucinate a better version" of your project—one that doesn't actually exist on your hard drive. By the time you realize it, you’ve spent an hour debugging code that refers to libraries you don't even have installed.

Conclusion: The Sovereign Developer
The future belongs to the Sovereign Developer. This is the developer who doesn't rely on cloud-based "memory" or expensive, black-box "Pro" features. They build their own tooling. They understand that the AI is a high-speed engine, but Context is the fuel.

If you are still copy-pasting single files into a chat window, you are working for the AI. It’s time to flip the script.

Don't take my word for it. Run the script above on your messiest, most complex local repository tonight. Take that output, paste it into GPT-o1 or Claude 4, and ask it to find a logic error.

You’ll see the difference in the first response.

Is Prompt Engineering dead, or are we just getting started? Change my mind in the comments below. I’ll be replying to the most controversial takes all week.

Top comments (0)