Every “AI does the paperwork now” story has to survive one question from an engineer, which is: fine, but where exactly is the model, and what is it allowed to touch.

Here is that answer for a system my team at Aditi built for a staffing client. A recruiter uploads one document. Out comes a ZIP of finished employment letters, on the correct templates, with the compensation breakdown calculated and every component adding up.
There are four separate calls to a language model in that pipeline. None of them does arithmetic. None of them writes a document from scratch. The interesting design work was almost entirely about deciding what to keep away from the model, and I want to walk the pipeline in order.
Step 1: the upload is not trusted
The document arrives as a Word file or a PDF from whoever the recruiter is. It is size-capped and the text is extracted server-side before anything else happens.
This is unglamorous and it is the correct first step for the same reason it always is: the file is the least trustworthy thing in the system, and the model is the component least equipped to be sceptical about it. A language model given a document containing instructions will consider following them. The mitigation is boring. Extract text, pass text, never pass a file handle to something that reasons.
Step 2: the first call reads, and is not allowed to write
The extraction call takes the document text and returns a structured object: candidate details, contract type, which optional letters are needed, the roles list, the compensation figure.
Two things are worth pulling out of this step.
It returns data, not prose. The output is a JSON contract with named fields, and every field has a specified shape. Not because JSON is fashionable, but because the next step in the pipeline is code, and code needs an integer where the document says “20 lakhs”.
Most of the prompt is defensive, not instructive. The part that says what to extract is short. The part that constrains how is long, and it is long because each clause was added after something came out wrong. Seven separate instructions guard the property that the number of roles out equals the number in. Explicit conversion examples handle the fact that money is written in a local dialect. An instruction to preserve line breaks in an address exists because a flattened address is still correct and looks machine-generated on a printed page.
I have written about that extraction step in more detail separately, because it turned out to be the hardest part of the system and I had scoped it as the easiest.
Step 3: the calculation, with the model deliberately absent
The compensation breakdown is computed in plain C#. No model, no prompt.
The client asked why. The short version of my answer: if this number is wrong, nobody finds out during testing. They find out three weeks after somebody starts a new job, when the payslip does not match the letter they signed, and the person who discovers it is the least able to absorb the error.
The design has one property that makes it self-checking. Most components come off a banded ladder or a statutory percentage, and then one component is not a rule at all:
result.ExecutiveAllowance = Math.Ceiling(monthlyCTC - fixedComponents - totalEmployerContributions);
It is the remainder. Everything else is calculated, and the last component absorbs whatever is left so the parts add back to the agreed total exactly. The letter always balances, and if an earlier rule is wrong the error surfaces visibly in that one line rather than disappearing.
This step is also where the system’s most instructive bug lived. There is a threshold in one allowance rule where the rate jumps sharply, and the original comparison put the boundary value on the wrong side:
Fix HRA giving 5% at exactly CTC = 5,00,000
Exactly one input was affected. Every other value in the range was right, which is why review missed it. A <= where a < belonged.
I keep that commit in mind when arguing this design, because it is the honest counterweight. Determinism did not make the code correct. What it bought was that the defect was in one readable place, fixable in one character, and provably fixed afterwards by rerunning the old inputs. The same error inside a prompt would have presented as “it is usually right near that boundary”, which is not a defect anyone can locate.
Step 4: the second and third calls write, and are not allowed to read
Two more model calls handle language, and they are separate from each other on purpose.
One refines the roles and responsibilities into consistent phrasing, because they arrive written by different recruiters in different registers and a letter with three voices in it reads as assembled.
The other compresses individual lines to fit the physical space in the template. That call takes a character budget and rewrites a single responsibility to fit it. That is a real constraint from the document, not a stylistic preference: the template has a box, the box has a size, and text that overflows it breaks the page.
Splitting these from extraction was not the original design. The first version did more in fewer calls, which is cheaper and reads better in a diagram, and it was wrong for a reason worth stating plainly: when one call both reads and writes, you cannot tell which behaviour caused a bad output. If the roles come back subtly rephrased and one is missing, was that a reading failure or a writing failure? With one call there is no way to know, and no way to fix one without disturbing the other.
Separating them costs latency and API calls. It buys the ability to debug. On a pipeline where a human reviews every output anyway, that is not a close decision.
Step 5: templates, not generation
The letters are real Word templates with placeholder tokens. The pipeline fills tokens. The model never produces a document.
This is the constraint that most surprises people, and it is the least negotiable thing in the system. These documents are legal instruments. The clause about notice period is not something to be paraphrased fluently. It is a clause that legal signed off, and it must appear identically in every letter, forever.
The model writes the parts that are genuinely about this person. The template holds the parts that are about the company, and those are never regenerated.
There is a small piece of evidence in the history that the template layer has its own difficulty, unrelated to AI:
If any component amount is zero, that component row should not appear in the offer letter.
A component switched off was rendering as a row showing zero. Arithmetically correct, and it tells a new employee they have a benefit worth nothing rather than that they do not have it. The fix is in the rendering layer where it belongs.
Step 6: one ZIP
Everything for one candidate is written to a timestamped folder, along with the extraction JSON from step 2, and delivered as a single archive.
The extraction artifact sitting next to the letters is the detail I would defend hardest. It means “why does this letter say that” always has a mechanical answer: open the extraction for that run and read what the model saw. Without it, every dispute becomes speculation, and with a probabilistic component in the pipeline that speculation never resolves.
The shape of it
Four model calls, one deterministic engine, a library of real templates, and an audit artifact per run.
The pattern underneath is not specific to letters. It is a division of labour by consequence of error, not by difficulty:
- Ambiguous input written by humans goes to the model. Nothing else does that job.
- Anything with a legal or financial consequence goes to code, where it can be read, tested and fixed in one place.
- Reading and writing are separate calls, so a bad output can be attributed.
- Fixed language lives in templates and is never regenerated.
- Every probabilistic decision leaves an artifact behind.
The first version of this had fewer moving parts and was harder to trust. Each split we made cost something measurable and bought something that only shows up on the day it goes wrong.
The trick is not making the model do more. It is being specific about what it is not allowed to touch.
