I've been building a pipeline that generates medically accurate cases for a simulated consultation platform. Doctors use these cases to practise for the Simulated Consultation Assessment, a key exam to get qualified as a GP. During the exam, actors are brought in to play the role of patients and the doctors are assessed on how well they conduct the consultation. The platform simulates this in a cost and time effective way, allowing the doctors to have a voice conversation with an AI patient and their performance is assessed by another AI. The cases need to be clinically sound, pedagogically useful, and structurally compatible with the web application.
During the prototyping phase, work was spread across Claude chat sessions, Python scripts, Google Drive, and multiple team members. Some steps were automated, others were done by hand, others were done by an AI in a chat window and copy-pasted into JSON files. It worked for proving the concept, but formalising it into a repeatable data transformation pipeline requires a bit more finesse than a simple 'Claude, turn this into a pipeline'.
That's what this article is about. Not the pipeline itself, but the context engineering that had to happen before Claude could build anything useful.
Why you can't just throw everything at the model
The lazy approach is to dump all your documents, code, and data into a conversation and say "work it out." I've tried variations of this and it doesn't work! Sad times :(
Context isn't just information. It's knowing which parts of the research doc were aspirational versus which parts got implemented. It's knowing that a field was renamed in your head three weeks ago but not in the codebase. It's knowing that when your colleague generated some data, a field wasn't strictly controlled and can contain data that doesn't directly map to the field name. It's knowing that another field was being used incorrectly and that this is a known issue you haven't fixed yet.
None of that is in the code. None of it is in the documents. It's the accumulated understanding of the person who did the work. And if you don't find a way to transfer it, the model will fill in the gaps with its own well-meaning yet completely incorrect assumptions.
Step One: Give the Agent some Background
My first step was to write a single markdown file background.md that described the overall process, the key definitions, and crucially, all the quirks. What work had been done, by whom, using what tools. Where the data lived. What the known issues were. What the working assumptions were. The discipline of writing this document was valuable on its own. It forced me to articulate things I'd been carrying around implicitly.
The goal was to give Claude the honest picture, that this is a first draft built on first drafts, that there's uncertainty baked in at every stage, and that the naming isn't consistent. I also included all the links it would need: links to research documents, code repos, data files, commit hashes for specific decisions. Including the links in this document allows Claude to fetch these in the later stages as and when it needs to - a process called "just in time" context.
AI can only amplify the thinking that you have done. One bad line of research compounds into a bad plan, which compounds into a thousand bad lines of code. Getting the context right at this stage is crucial.

Step Two: Create a Target Model
With the goal being to create a data transformation pipeline, I first need a detailed plan of how this should be implemented. This meant creating an accurate target state data transformation model showing how every attribute flows end-to-end through a multi-stage transformation pipeline where the data incrementally gets transformed into the final desired case. From this model I would build my data transformation pipeline. If the task were simpler I'd usually skip to implementing the pipeline itself, but the data transformation model really adds value as it is much easier to reason about than a python pipeline and helps discuss key domain logic decisions with my team mates.
My first attempt was to try and model the manual workflow, every step that had actually been taken, including the scrappy ones. This proved to be the wrong approach. It was too complex, and it made more sense to just try and capture "what we want the pipeline to do." So I pivoted to modelling the target state instead, accepting that there could be some manual steps that are missed. Nothing is perfect, and I could always reconcile the drift later.
Planning the data transformation model alone took 5+ hours and the plan went through 7 updates, starting with some complete rewrites due to incorrect assumptions made by Claude and finishing with minor tweaks to get it just right. The plan grew from a relatively simple schema spec to a 700+ line document that captures every stage of the pipeline, the prompt section structures, and flags every gap or fuzzy relationship where the mapping isn't clean.
The whole purpose of this step was alignment. Not just "here's what I want you to build" but "here's how I think about this domain, here's what's certain and what's uncertain, here's where the gaps are." Anthropic describe context engineering as finding the smallest possible set of high-signal tokens that maximise the likelihood of the desired outcome. For my case, I'd describe it as building a shared mental model between me and the machine.
Step Three: Generate the deliverable
After the planning, the actual generation was the easy part. Claude implemented the plan in about 20 minutes to give me a fully functioning data transformation model. The data model had two layers: a machine-readable JSON bundle that serves as the single source of truth, and a self-contained HTML viewer you can open in the browser with colour-coded categories, interactive lineage tracing, hover tooltips, and all the other bells and whistles that make for a good read.
This is the part that feels like magic to people watching from the outside. But the magic isn't in the generation, it's in the 5+ hours of context work that preceded it. The model wasn't being creative. It was faithfully expanding on a plan that had been meticulously aligned to my intent. What I've taken away from this
What I've Taken Away from This
Context pollution is real: It's the data engineering principle of garbage in, garbage out, applied to AI. If you give the model dirty context, incorrect assumptions, stale names, missing relationships, you get dirty output. And unlike a database where you can query to find the bad records, bad context produces bad output that looks right. The model will confidently generate a data model with the wrong field lineage and it'll be internally consistent. You'll only catch it if you already know what right looks like.
Don't outsource the thinking: I've seen people describe AI as a replacement for understanding. In my experience, it's the opposite. You need to understand your domain more deeply than before, because you need to compress that understanding into a form the model can work with. The research, the planning, the context curation, that's the real work. The generation is the payoff.
The right altitude matters: Anthropic talks about finding the Goldilocks zone between overly rigid instructions and vague high-level guidance. I found this applied not just to prompts but to every piece of context. Sometimes you need a full schema definition. Sometimes you need a simple note that says "this field is fuzzy." Sometimes you need a worked example. The skill is knowing which altitude each piece of information needs to live at so the model can actually use it.
Planning is leverage of intent: The ratio of planning time to generation time in this project was roughly 15:1. That sounds extreme, but it meant the generation step required almost no iteration. Claude didn't go off in the wrong direction because there was no ambiguity about what the right direction was. Every hour spent on the plan saved multiples in rework.
Clear sessions force clean context: One practice I've adopted from reading other people's workflows is starting implementation in a clean session. It sounds minor, but it forces you to think about what context needs to be carried forward and what can be left behind. If you can't summarise it for a fresh session, it probably isn't clean enough. And if the context isn't clean, neither will the output be.
I'm still early in this pipeline build. The data transformation model is step one of a longer process. But the approach, invest heavily in context, align before generating, surface uncertainty explicitly, has already changed how I think about working with AI on complex tasks. The bottleneck isn't the model's capability. It's the quality of context you give it.