Your agent has a 200,000 token context window, you wrote a clear instruction, and the answer is still wrong. The model is rarely the problem. What you put in front of it usually is, and fixing that is what context engineering for web content actually means.
The practice is simple to state. Decide what an AI agent sees when the source is a webpage, a PDF, or a code repository, then get that material into the prompt in a form the model can use. Prompt engineering shapes the instruction. Context engineering shapes everything the instruction operates on.
That distinction stopped being academic once agents started doing multi-step work. A single chat message forgives a messy paste. An agent running ten tool calls against the same polluted context does not.
This guide covers where the term came from, why clean input beats raw HTML and PDF, three conversion workflows that cover almost every real source, how to budget tokens, and the failure modes that quietly wreck output.
What You’ll Learn About Context Engineering for Web Content
This guide is written for developers and AI power users who already write decent prompts and have noticed that the bottleneck moved somewhere else.
You will finish with four things installed.
- The framing. What context engineering means in 2026, where the term came from, and how it differs from prompt engineering in practice rather than in theory.
- Three workflows. Webpage to context, PDF to context, repository to context. Each one with a concrete tool and a concrete output.
- A token budget. A way of deciding how much context is enough, and a before and after number that shows what cleaning is actually worth.
- A failure checklist. The five ways context goes bad, and how to spot each one before it reaches the model.
No agent framework tutorial. No vector database comparison. Just the layer between “I found the source” and “the model has what it needs.”
What Is Context Engineering? (The 2026 Framing)
The term went mainstream in June 2025, when Shopify CEO Tobi Lütke posted that he preferred “context engineering” to “prompt engineering” because the real work is the art of providing all the context needed for a task to be plausibly solvable by the model. Andrej Karpathy amplified it within a day, and the phrase stuck across the agent-building community.
Anthropic later published a practitioner framing in its engineering blog, describing context engineering as curating the smallest set of high-signal tokens that maximizes the chance of the desired outcome. That framing matters because it names the constraint. Context is finite, attention is finite, and every token you add competes with every other token.
Here is the cleanest way to hold the distinction.
A prompt is the instruction. “Summarize the pricing changes in this document and flag anything that affects enterprise customers.”
Context is everything the instruction operates on. The system prompt, the tool definitions, the conversation history, the retrieved documents, and the source material you pasted in.
You can write a flawless instruction on top of bad context and get a confidently wrong answer. The reverse is more forgiving. Good context with a sloppy instruction usually still lands somewhere useful.
| Prompt engineering | Context engineering | |
|---|---|---|
| Object of work | The instruction | Everything else in the window |
| Typical fix | Rewrite the ask, add examples | Remove noise, convert format, retrieve less |
| Failure looks like | Model misunderstands the task | Model answers the wrong source |
| Scales with | Task complexity | Source volume and agent turns |
Both matter. But if you are building anything that runs more than one turn, context is where the leverage is.
Why Clean Input Beats Raw HTML and PDF
The model only ever sees what arrives in the prompt. Not the page you were looking at. Not the document as it renders on screen. Just the character stream.
Here is what arrives when you copy a product changelog straight out of a browser with the markup intact:
<body class="theme-light">
<header class="topbar"><a class="logo" href="/">Meridian</a>
<ul class="menu"><li><a href="/pricing">Pricing</a></li><li><a href="/changelog">Changelog</a></li></ul>
</header>
<div class="banner banner--promo">Meridian 4.0 ships next month. <a href="/webinar">Save your seat</a></div>
<main class="release-notes">
<h3 class="release-title">Version 3.8.2</h3>
<ul class="release-list">
<li>Scheduled exports now retry three times before giving up.</li>
<li>Fixed a timezone drift in the weekly digest email.</li>
</ul>
</main>
<div class="newsletter-cta"><input placeholder="Work email"><button>Subscribe</button></div>
<script src="/static/telemetry.min.js"></script>
</body>
And here is the same content after conversion:
### Version 3.8.2
- Scheduled exports now retry three times before giving up.
- Fixed a timezone drift in the weekly digest email.
Same information. A fraction of the tokens. Three things improve at once.
Signal density goes up. The ratio of meaning to markup flips. On a typical content page, the article body is 15 to 25 percent of the raw HTML. Everything else is layout the browser needs and the model does not.
Structure survives. A ### in markdown is unambiguously a heading. A <div class="banner banner--promo"> is a naming convention, and the model has to infer meaning from a class string that could say anything. Headings, lists, tables, and fenced code blocks all tell the model how to segment what it is reading, and markdown carries that signal in a handful of characters.
Attention stops splitting. Models attend most strongly to the start and end of their input. Padding the middle with menu labels and promo banners pushes real content into the weakest position in the window.
The longer argument for the format itself lives in the guide to markdown as LLM input. The short version: markdown is the lowest-overhead format that still carries structure, which is exactly the trade context engineering wants.
Workflow 1: Turning a Webpage into Context
The most common source is a page you are already looking at. Documentation, a changelog, a competitor’s pricing page, a long-form article you want the model to reason over.
The bad version of this workflow is select all, copy, paste. That drags in the nav, the sidebar, the cookie notice, the newsletter modal, and the related-posts block at the bottom.
The good version runs an extraction pass first. Readability-style extraction scores DOM nodes by how likely they are to be content instead of boilerplate, keeps the high-scoring subtree, and throws away the rest. Then an HTML-to-markdown conversion preserves the structure that survived.
The CopyMarkdown extension does both steps in one click on whatever tab is open, and it does the conversion locally in the browser rather than sending the page to a server. That matters when the page is behind a login, on an internal wiki, or otherwise not something you want leaving the machine.
Before you paste, run a three-item check on the output:
- Does it start at the content? If the first lines are menu items, extraction picked the wrong subtree. Delete the top.
- Did the headings survive? If the whole page came out as one flat block of prose, the model has nothing to segment on.
- Is anything in there you do not need? Author bios, related-post lists, and comment threads are almost never worth their tokens.
Ten seconds of cleanup at this step saves you from debugging a bad answer three turns later.
Workflow 2: Turning a PDF into Context
PDFs are the hardest common source, because a PDF is not a document in any structural sense. It is a set of drawing instructions. Place this glyph at these coordinates. The format does not know what a paragraph is.
That means extraction quality varies enormously with how the file was produced.
Text-layer PDFs convert well. Anything exported from Word, LaTeX, or a web page has a real text layer underneath the rendering. Drop it into the PDF to markdown converter and you get headings, lists, and tables back as markdown. The tool takes files up to 20 MB, also handles DOCX, PPTX, Excel, HTML, CSV, and JSON, and deletes the upload immediately after conversion.
Scanned PDFs are a different animal. If the file is images of pages, there is no text to extract until OCR runs over it, and OCR introduces its own errors. Column layouts interleave. Table cells lose their rows. Footnote markers land mid-sentence.
Be honest with yourself about which one you have. Open the file and try to select a sentence. If nothing highlights, you are in OCR territory and the quality ceiling is set by that step, not by the converter.
Two practical habits help regardless of source quality.
Convert the section, not the file. If your question is about pages 40 to 47 of a 200 page report, split first. This is the single highest-return move in the entire PDF workflow.
Read the output before you trust it. Skim the converted markdown for collapsed tables, sentences broken across page boundaries, and repeated running headers. Fix them by hand. It takes a minute and it prevents the model from citing something the document never said.
Workflow 3: Turning a Repo into Context
Code is context too, and it is the case where “just paste it” breaks down fastest. Nobody is copying forty files into a chat window one at a time.
The flattening approach works better. Walk the repository, skip everything that carries no meaning for a model, and assemble what is left into a single markdown document with a directory tree at the top and fenced code blocks below.
The GitHub to markdown converter does this from a URL. It accepts a whole public repository, a single directory, or one file, keeps only text and code files, and honors the repo’s .gitignore, so build artifacts and dependency folders stay out. Large monorepos can exceed its processing limits, which is usually a signal that you should be pointing it at a subdirectory anyway.
Scope the conversion to the question. If you are asking about the auth layer, convert src/auth/ rather than the whole tree. A focused 6,000 token export beats a complete 90,000 token one for almost every real question.
There is also a persistent side to repository context, and it is worth setting up once. Coding agents now read a markdown file at the repo root before responding to anything: CLAUDE.md, AGENTS.md, or GEMINI.md depending on the tool. That file carries the build commands, the conventions, and the forbidden actions that a model cannot infer from the code itself. The guide to AGENTS.md and CLAUDE.md covers the convention and what belongs inside.
Flattening is how you hand an agent a codebase for one task. The instructions file is how you stop re-explaining the project on every conversation. Most teams need both.
Token Budgeting: How Much Context Is Too Much
Big context windows created a bad habit. When the limit was 4,000 tokens, you were forced to curate. At 200,000 or a million tokens, dumping everything feels free.
It is not. Long-context benchmarks consistently show quality degrading well before the advertised ceiling, and the degradation is worst for content sitting in the middle of the window.
Here is what cleaning is actually worth on a single source. A typical documentation page, measured three ways:
| Input | Approximate tokens | What is in there |
|---|---|---|
| Raw HTML, copied with markup | 8,400 | Content plus nav, sidebar, scripts, inline styles |
| Browser copy-paste, text only | 3,100 | Content plus menu labels, footer text, cookie notice |
| Extracted and converted to markdown | 1,250 | Headings, paragraphs, lists, code blocks |
Roughly 85 percent of the raw version was structure the model could not use. Multiply that across the eight pages you wanted the agent to reason over and the difference is 67,000 tokens against 10,000.
A budget that works for most agent tasks:
- System prompt and tool definitions: whatever they cost, and audit them, because they are in every single turn.
- Source material: the largest slice, but curated. Two well-chosen documents beat ten scraped ones.
- Working room: leave at least 40 percent of the window free for the conversation, tool results, and the model’s own output.
If a task genuinely needs more source material than that allows, the answer is not a bigger paste. It is retrieval, summarization, or progressive disclosure. The guide to reducing LLM token usage walks through the specific strategies for long documents.
The rule of thumb: curate for quality first, and count tokens for cost only once you are running at volume.
Common Failure Modes in Context Engineering for Web Content
Five patterns account for most of the bad output. All five are visible before you hit send, if you look.
Pasting raw HTML. The most common failure and the easiest to fix. Markup with inline styles and layout divs is the most expensive, least informative thing you can put in a context window. If you can see angle brackets in your prompt, stop and convert.
Drowning the window in page chrome. Subtler than raw HTML, because plain-text copy-paste looks clean. It is not. Menu labels, breadcrumb trails, footer link lists, and “you might also like” blocks all survive a text copy, and across several pages they repeat, which teaches the model that boilerplate is the important recurring theme.
Stale and duplicated context across turns. In a long conversation, people re-paste the same document because they are not sure the model still has it. Now two versions are in the window. When they differ, and they usually do after an edit, the model has no way to know which one is current. Refer back to what you already sent instead of sending it again.
Trusting garbled PDF output. Every PDF converter, ours included, produces flatter output than the original document. Tables collapse. Multi-column layouts interleave.
Scanned pages are worse, because OCR errors read as plausible words. The model will happily reason over garbage and cite it with confidence. Read the converted markdown before it becomes context.
Losing provenance. When four sources go into a window with no labels, the model blends them and you cannot audit the answer. Put a one-line header above each source with the URL and the date. It costs almost nothing and it makes every downstream citation checkable.
The pipeline version of all five problems, with deduplication, chunking, and refresh strategy, is covered in the guide to preparing web content for RAG. Retrieval systems are context engineering with the curation step automated, which means the failure modes are identical and just harder to see.
What to Read Next
Context engineering is mostly unglamorous work at the input layer. Extract, convert, trim, label, then prompt. The models keep getting better at reasoning over what you give them, and steadily less forgiving of being given the wrong thing.
For the format argument in full, see Markdown for LLMs: Prepare Web Articles for AI.
For token strategy on long documents, see How to Use Fewer Tokens and Get Better LLM Results.
For automating the curation step in a retrieval pipeline, see How to Prepare Web Content for RAG Pipelines.
For the repository-side convention that gives coding agents standing context, see CLAUDE.md, AGENTS.md, GEMINI.md.
And for the three workflows above, the tools are free and need no account: the CopyMarkdown extension for any page you have open, the PDF converter for documents, and the GitHub converter for repositories.