← All notes

AI

How to put basic guardrails on an agentic legal system

Andrew Castillo

· 5 min read

How do you put guardrails on an agentic AI system?

Let the AI do the parts that need judgment, then check what it hands back against something fixed before the next step touches it. A plain yes-or-no check after each step catches the run where it gets 2 plus 2 wrong and sends that step back, so the mistake doesn't travel down the line.

Back in January I was answering a set of screening questions for a project, and one of them was about multi-agent AI systems. Had I built one, and how did the agents work together?

I had. I built a system for a law firm's litigation team that does the first round of research on a lawsuit response, the kind of work that usually goes to junior attorneys. The documents land in a Google Drive folder. The text gets pulled out, with OCR when it's a scanned PDF. Then a set of AI agents takes it from there, and at the end a draft response shows up in Drive for an attorney to review.

While I was walking through it, I named the part that makes the whole thing hold up: the guardrails between the agents.

The guardrail between every agent

The first agent looks at what came in and works out how the folder should be structured. That takes some reading and interpreting, so it's a reasonable job for AI.

Before anything moves to the next agent, that output hits a check. The check doesn't interpret anything. It asks one question. Is this either this structure or that structure? Yes or no.

If it's yes, we move on. If it's no, it goes back through the agent again.

That's how I handle every agent in that system. The agent can use AI to come up with its output, and then the output has to match a specific set of criteria before anything downstream gets to use it. After the folder step there's a lot of plain business logic. Then a research agent searches case law through CourtListener and Google Scholar, and what it brings back gets validated too. Only after all of that does the team get a message that a new response is ready.

On the call I put it in plain terms: it's fixed data I need to validate against. It's either one or zero.

An n8n workflow canvas: a Google Drive trigger feeds OCR text extraction, then an AI agent with Google Drive folder tools hands its output to a Switch node that checks it before the next step.
The n8n workflow, with identifying details blurred.

Why I don't let the AI check its own work

The way I explained it: AI is probabilistic. If you ask it 2 plus 2 a million times, there are probably a couple of times it gets it wrong. If you put 2 plus 2 into a calculator, you get the right answer every single time.

A lot of what happens in a system like that is calculator work. Is the output in the shape it's supposed to be in? Does it have the pieces the next step expects? Nothing about those questions needs judgment, and I don't want judgment anywhere near them. So the AI handles the reading and interpreting, and the checks around it are fixed rules.

I work the same way with AI coding tools day to day. A few days after that interview I was walking a client through how I use them, and I told him that when I know something has a very set workflow, I build a script for it and have the agent call that script. Then it's not messing up. The agent decides when to run it, and the steps stay the same every time.

Where a person comes in

The next question was when the AI should act on its own and when it should hand off to a person. There's no one-line answer. That decision belongs to the business, because it depends on how much risk they're willing to take.

What I can do is turn their answer into a rule. Some AI tools will tell you how confident they are. The example I used was a hypothetical: you send it a picture, ask what's in it, and it comes back with "a cat, 95% confident." If the business decides anything under 95% goes to a person, that threshold becomes one more fixed check. It has a person on the other side of the "no" instead of another try.

On the legal system, the last step is a person every time. The draft goes back into Drive and an attorney reviews it before it goes anywhere.

That line can move, too. The models keep getting better, so what needs a person today might not need one later. Because the threshold lives in a rule outside the AI, moving it means changing the rule. The rest of the system stays the same.

What it bought us

When I described it in January, it had been in production for about six months with around ten people using it. I had the time for a first-draft response down to roughly 20 minutes, with room to go faster through a couple more integrations and a more refined process.

The checks are a big reason I'm comfortable handing something like that to a team. When a step gets it wrong, the mistake doesn't quietly roll into the next three steps. It gets caught at the step where it happened, and that step runs again.

How to put guardrails on your own system

Your version will look different. Say you run a recruiting desk and want AI pulling details out of intake calls into your CRM, or a coaching program that wants a first draft of each client's check-in summary. Those are hypothetical, and the first question is the same either way.

After each step, what does "right" look like in a way a simple rule could check? Are the required fields filled in? Is it in the format the next step expects? Does it match a record you already have?

Write those checks down before you pick any AI tool. Then the AI can be wrong once in a while, and the system catches it at that step.

not sure where to start —

Agents you can trust start with checks you can see.

Fifteen minutes. Walk me through the process you want agents running, and I'll show you where the checks go so a bad step never reaches a client.

read next —