
This blog is written by AI for SEO
How to Make AI Agents Follow Your Business Rules
To make AI agents follow business rules, stop writing the rules as prompt text and start enforcing them as declarations over linked entities: checked before a write commits, with violations sent to a person and every fact traced to its source. A prompt asks the model to behave. A constraint check makes the wrong write impossible to commit unnoticed.
The loop is the same in any stack, and this guide walks through it step by step: declare, link, check, review, trace. After that it shows where Helix Foundry does each step, so you are not hand-building the plumbing. Foundry is the open-source app (Apache 2.0) that connects your databases, tools and documents and drafts one ontology over them. HelixDB is the database it loads into.
Why prompts alone do not make an agent follow business rules
Prompts alone do not make an agent follow business rules because the model decides on every call whether to comply, and it can report compliance it never achieved. A system prompt that says "never approve a refund over $5,000 without a manager" is context the model reads, weighs against everything else in the window, and may ignore or paraphrase away.
A worked example from AWS makes the same point: an agent can hallucinate that an operation succeeded even when it violated a business rule, and the fix is a check that runs outside the model, intercepting each tool call before it executes. In their demo, an agent with no hook confirmed a booking without payment and booked a hotel for more guests than the limit allowed. The same model and tools with a pre-execution check blocked all three invalid operations.
The lesson is architectural. Rules belong in code that sits between the agent and your data, not in the text the agent reads. Frameworks like LangChain, Open Policy Agent, Drools, Camunda and NeMo Guardrails all take some version of this position: validation runs outside the LLM. What most of them leave to you is the part that actually decides whether a rule can be written at all: a shared, linked model of the entities the rule talks about.
Write the rules down as declarations over entities, not as prose
Write each rule as a declaration over typed entities and their links, so a machine can evaluate it and a person can read it. "Be careful with large invoices" is prose. "An Invoice linked to a Customer with status = suspended must not move to approved" is a declaration.
Use two kinds of statement. Derivation rules produce facts from facts you already have: a Customer is an enterprise account if its contract tier is enterprise. Constraints state a condition the data must satisfy: an Invoice over the approval limit must link to an Approval by a person with the right role. Keep each one small, named, and tied to entity types rather than to a table or a prompt.
A short list for a typical ops team:
Every Order links to exactly one Customer.
An Invoice total must equal the sum of its Order lines.
A refund above the approval limit needs a linked Approval.
A Vendor on the blocked list cannot receive a payment.
A contract's renewal term cannot be shorter than its notice period.
Notice that none of these mention an agent. That is the point. The same declarations hold whether a person, a script or an agent makes the change.
Link the same customer, order and invoice across systems before you enforce anything
Link the same customer, order and invoice across systems first, because a rule over entities can only fire on entities that are actually connected. If Stripe knows "Acme Corp", Postgres knows customer 4417 and a contract PDF says "Acme Corporation Ltd", a constraint about Acme's approval limit has nothing consistent to check against.
The approach works in any stack. Pick a match key per entity type (a billing ID, a normalised email domain, a tax number). Write the mapping from each source into the shared entity types. Run an orphan check: which Invoices have no Customer, which Customers appear in only one system. Treat every orphan as either a missing link or a real data problem, and decide which before enforcing anything. Skip this and your rules either never fire or fire on the wrong record.
This is also where drift bites. Columns get renamed, IDs change, duplicate customers appear, and links quietly go stale. We cover the detection and repair loop in self-healing ontology: keeping links right as data drifts, and the cross-system matching step in linking the same customer across Stripe and Postgres.
Check constraints before a write commits, and send violations to a person
Check constraints at the commit boundary, before the write lands, and route any violation to a person instead of letting the agent retry its way around it. Enforcement at read time tells you something was wrong after the fact. Enforcement at write time keeps the bad state out.
The shape of the loop:
The agent proposes a change (approve an invoice, update a contract term, issue a refund).
The change is evaluated against the declared constraints over the linked entities.
If every constraint holds, the write commits.
If one breaks, the write does not commit silently. It lands in a review queue with the rule that failed, the entities involved and the evidence.
A person approves an exception, fixes the data, or rejects the change.
Two design choices matter. First, the agent receives a rejection, not a way to override. If the model can edit the rule or the threshold, it is a prompt again. Second, an uncertain call goes to a human rather than to a guess. A violation that nobody sees is the same as no rule.
Keep every fact traceable to the row or document quote it came from
Keep every fact traceable to its source, so that when a rule fires, a reviewer can see which row or which sentence in which document produced the data it fired on. A flag that says "invoice violates policy" with no evidence gets ignored. A flag that points to the contract clause and the billing row gets acted on.
In practice that means storing, next to each fact, a pointer to its origin: table and primary key for structured data, document and quoted passage for extracted facts. It also means a derived fact inherits the provenance of the facts it came from. When someone asks "why did the agent hold this payment?", the answer is a chain back to source, not a model's explanation of itself.
Traceability also protects you from the opposite failure: a model confidently extracting a number from a PDF that is not in the PDF. If every extracted value carries its quote, a reviewer can check it in seconds. For the extraction side, see how to extract an ontology from contracts and PDFs.
Doing this in Helix Foundry: connect, generate an ontology, review Rules, read Rule breaks
Helix Foundry runs this loop for you: connect your sources, have it draft an ontology with types, links and mappings, review the proposed Rules, load, then read Rule breaks and Needs review. It never writes to your sources.
To run it locally:
git clone https://github.com/helixdb/helix-foundry.git
cd helix-foundry
docker compose up -d --waitThen open http://localhost:3000. You need Docker with Compose v2 and ports 3000 and 8333 free. Or use the hosted app at foundry.helix-db.com and pick Set up with your agent. The local install is single-user on localhost with no sign-in, so keep it off the network.
The flow:
Connect data. Add a source such as PostgreSQL, MySQL, Amazon S3 or Stripe, test it and sync its tables. Documents come in too.
Generate an ontology. Foundry's agent drafts types, links and mappings from your synced tables and recent documents, which links the same customer, order or vendor across systems.
Review the Rules tab. In a version's Rules tab you see ontology rules, which derive facts from existing data, and constraints, which state conditions the data should satisfy. Generated rules are proposals. Check each against your real business requirement before you make that version current.
Make it current and load. The current version is the one used for the next load.
Read Rule breaks. After loading, Rule breaks lists the records that violate the current version's constraints. They are surfaced for people to review, not silently corrected.
Work Needs review. Unresolved document or entity issues show up under Needs review on the record.
To change a rule, open the version's Edit tab, stage the changes, preview them, create a new version, and make it current. Every fact stays tied to the row or document quote it came from. Details are in the Foundry docs. For the same model reached from an agent, see how to give AI agents context about your business.
Trade-offs: what Foundry surfaces and what a person still decides
Foundry surfaces the breaks and the evidence; a person still decides what the rule should be and what to do about a violation. That split is deliberate.
What Foundry gives you: a drafted ontology, proposed rules and constraints, a Rule breaks list after each load, a Needs review queue, and a trail back to the source row or quote. What it does not do: decide that your $5,000 approval limit is correct, accept an exception on your behalf, or write corrections back to your source systems.
Two practical costs. Generated rules are proposals, so someone who knows the business has to read the Rules tab before a version goes live, and a wrong constraint is as wrong as a wrong prompt. And Rule breaks reflect the last load, so they are as fresh as your last sync. If you need a block at the instant an agent acts, you still wire your agent's tool calls to check before they execute; Foundry gives you the model and the declared rules to check against, and the review queue for what fails.
Start with one rule and one source
Prompts ask an agent to behave. Declared constraints over linked entities, checked before a write commits and backed by source evidence, make the rule hold. Pick one rule your team already enforces by hand, such as an approval limit or a blocked vendor, run Foundry locally from github.com/helixdb/helix-foundry, connect one source, and see whether it shows up under Rule breaks. Then star the repo and add the next rule.