Combine LLM Output with Rule-Based Decisions: Hybrid Patterns

Nov 27, 2026 | AI Integration

Combine LLM Output with Rule-Based Decisions: Hybrid Patterns

To combine LLM output with rule-based decisions, let the model do the interpretation and let deterministic code make the decision. The model reads the messy input (an email, a scanned invoice, a free-text complaint) and turns it into structured, schema-validated fields. A rules layer then evaluates those fields against your business policy, decides, and routes anything ambiguous to a person.

The principle underneath is simple: the model never gets the final word on anything that must be consistent, auditable or expensive to reverse. What follows covers where the boundary goes, which hybrid pattern fits which workflow, and how to stop the two halves drifting apart in production.

Why not let the model decide on its own?

LLMs are excellent at what rules are terrible at. They can read a supplier’s idiosyncratic invoice layout. They can work out that a customer who writes the thing I ordered last Tuesday never came, sort it probably wants a reship rather than a refund. They cope with typos, mixed languages and forwarded email chains that would need hundreds of regular expressions to parse badly.

Rules are excellent at what LLMs are unreliable at. They apply the same threshold every time, explain exactly why a decision was made, and change behaviour the moment policy changes, without re-testing a probabilistic component.

Ask a model should this refund be approved? and you get an answer that is probably right, plausibly phrased and not guaranteed to be the same next month. Provider-side model updates, prompt edits and small input differences can all flip borderline cases, even at low temperature. When finance asks why refund 4471 was approved and 4472 was not, the model thought so is not an answer. It is not an answer for an auditor either, or for a customer invoking their GDPR rights around solely automated decisions that significantly affect them.

Security is the other reason. If a decision lives in the prompt, the input can argue with it. A limit enforced in code cannot be talked out of itself by a cleverly worded email or a poisoned document. Our guide to AI security and compliance for EU firms covers prompt injection in more depth, but the design consequence is short: the model may influence a decision, it should not be the thing that enforces policy.

The opposite extreme fails too. Pure keyword-and-regex systems on unstructured text grow an ever-longer exception list until nobody dares touch them. Hybrid design puts each tool where it is strong.

Five hybrid patterns that work

1. The model extracts, the rules decide

This is the default and the one to reach for first. Take a refund request inbox. The model reads each message and returns a fixed structure: intent, order number, claimed issue, requested remedy, and a short quote from the message supporting each field. The rules layer then takes over. It looks the order up in your system of record, checks the courier status and order value, and applies policy.

A policy might say that an undelivered order under €50 that is ten days past dispatch gets an automatic reship. Anything over €500 goes to a person, as does a third refund in 90 days for the same customer. The detail that matters is that the rules act on data from your systems, not on the model’s claims. The model says order 88213, and the rule checks that order 88213 exists, belongs to this customer and really is undelivered. The worked example of AI invoice processing follows the same shape: extraction by the model, matching and approval by deterministic logic.

2. Rules first, the model handles the residue

This inverts the first pattern. Deterministic matching handles the predictable bulk cheaply: known supplier templates, exact purchase-order matches, standard form submissions. Only what falls through goes to the LLM. It is cheaper, faster and easier to audit, because most decisions never touch a model. The downside is two code paths to maintain, and a rules path that grows greedy as people keep adding just one more special case. It fits best when an existing rules system already handles most cases and the pain sits in the long tail.

3. The model proposes, the rules validate

Here the model generates a candidate output that must pass a validation layer before it takes effect: a drafted credit note, a proposed delivery schedule, a database query or a set of tool-call arguments. The rules check that line items sum to the total, that dates fall in the future, that the discount is within the sales rep’s authority, and that the query is read-only and touches only permitted tables. On failure, either retry with the validation error fed back to the model, bounded to one or two attempts, or escalate. This is the core of deterministic guardrails for LLMs, and the pattern most agentic systems need.

4. Rules constrain what the model can choose

Rather than checking afterwards, narrow the options up front. A state machine decides which actions are valid in the current state, and the model only ever sees those. A support ticket in awaiting customer simply does not offer a close as resolved tool. A classification step only accepts values from an enum generated from your current product catalogue. Pattern three catches a class of errors after the fact; this one makes them impossible.

5. Rules decide, the model explains

The decision is fully deterministic. The model’s only job is to write the customer-facing explanation or internal summary from the decision record. This is the lowest-risk use of an LLM in a decision flow, and useful where tone matters, such as declining an insurance claim or a credit increase. One guard is essential: the generated text must not restate a different outcome from the one decided. Template the sentence that states the outcome, or check the draft against the decision record before sending.

Pattern LLM role Rules role Best for Main failure mode
Extract, then decide Turn unstructured input into typed fields Verify against systems of record and apply policy Inbound email, documents, forms Extraction errors that look valid
Rules first, model for residue Handle cases rules cannot match Process the predictable bulk Mature processes with a messy long tail Two diverging code paths
Propose, then validate Generate a candidate action or artefact Veto anything that breaks constraints Agents, drafting, query generation Retry loops and silent escalation backlog
Constrained choice Pick from a pre-filtered set Define which options are valid now Workflow agents with state Stale enums after catalogue or process changes
Decide, then explain Write the rationale or message Make the whole decision Customer communications, adverse outcomes Text that contradicts the decision

Designing the contract between model and rules

Every hybrid pattern depends on a clean interface between the probabilistic half and the deterministic half. Most production problems trace back to a sloppy contract here.

Make the model’s output a typed interface

Define a JSON schema with required fields, enums for anything categorical and explicit types for amounts and dates. Use the provider’s strict structured-output mode where it exists, validate again on your side regardless, and reject anything that fails rather than coercing it. Allow nulls, and make clear in the prompt that a null is preferred to a guess. A missing VAT number that routes to a human is far cheaper than an invented one that sails through. Our step-by-step build for integrating an LLM into your app walks through the schema and validation layer in code.

Do not trust self-reported confidence

Asking a model to rate its own confidence from 0 to 1 produces numbers that look precise and are poorly calibrated. Better signals come from things you can check deterministically:

  • Require an evidence quote for each extracted field, and confirm with a plain string match that the quote actually appears in the source.
  • Cross-check extracted values against systems of record: the supplier exists, the PO is open, the amount matches within tolerance.
  • For high-stakes fields, run two extractions (different prompts or models) and treat disagreement as low confidence.
  • Check cross-field consistency, for example that net plus VAT equals gross, or that the delivery date is not before the order date.

Keep rules out of the prompt and under version control

A prompt instruction like never approve refunds above €500 is advisory. Treat it as a hint that improves the model’s proposals, never as the control. The actual limit belongs in code or configuration that is tested, versioned and reviewed.

Where those rules live depends on who changes them and how often. A small, stable rule set is best as a plain, well-tested module. Rules that operations staff adjust can sit in decision tables, using the DMN standard or simply a reviewed config file. Authorisation-style rules shared across services can go in a policy engine such as Open Policy Agent. Pick the most boring option that fits; most SMEs need a tested module and a config file, not a rules engine with its own licence and learning curve.

Log the whole decision trace

For every decision, record the input reference, the model and prompt version, the raw model output, the validated fields, the rules version and which rules fired, the outcome, and any human override with a reason. That record is what lets you answer why six months later, and it is your best source of test cases.

Guardrails on actions, not just answers

Once the LLM is an agent calling tools rather than a function returning text, the rules move into the tool layer. Every tool call should pass through a deterministic gate before it executes. The gate can check an allow-list of operations, limits on amounts and rates, idempotency keys so a retried call cannot pay an invoice twice, and a mandatory approval step above defined thresholds. None of this depends on the model behaving. It holds even if the model is confused, manipulated or simply wrong.

The approval step is where hybrid systems meet human-in-the-loop design. Our article on human-in-the-loop approval patterns that scale covers how to keep that step from becoming a bottleneck. We use the same idea internally, with human-in-the-loop action tags that make AI agents easy to steer from a phone. Cases the rules reject also need somewhere sensible to go, and the flag, route and escalate structure in exception handling for automated workflows applies directly.

A checklist before you ship a hybrid decision flow

  1. Write the decision policy down in plain language and get the business owner to sign it off before any prompt is written.
  2. Mark each step as interpretation (model) or decision (rules). If a step is both, split it.
  3. Define the output schema with enums, types and nullable fields, and reject anything that fails validation.
  4. Verify every model-extracted identifier and amount against a system of record before a rule acts on it.
  5. Enforce limits, permissions and thresholds in code or config, never only in the prompt.
  6. Put a deterministic gate in front of every tool that changes state, with idempotency on anything financial.
  7. Define the escalation path, its owner and its expected response time.
  8. Build a golden set from real historical cases, covering per-field extraction accuracy and end-to-end outcomes.
  9. Log the full decision trace, including model, prompt and rules versions.
  10. Run in shadow mode alongside the current process and compare outcomes before letting the system act.

Where hybrid systems go wrong

The first trap is rule sprawl used to patch model errors. If you find yourself writing a rule like if the supplier is X and the extracted total ends in 00, recheck, the extraction is the problem. Fix the prompt, the schema or the document preprocessing. Rules should encode business policy, not compensate for a weak upstream step.

The second is silent drift. A model upgrade or prompt change can shift the distribution of extracted values without breaking any validation: every field still passes the schema, yet more cases now fall just under an auto-approval threshold. Monitor outcome rates (the auto-approved share, the escalated share, the override rate) and alert when they move outside a normal band. Pin model versions where the provider allows it, and re-run the golden set before every upgrade.

The third is testing the system only as a whole. Test the halves separately: field-level accuracy for extraction, unit tests for rules, then end-to-end replay of historical cases. When an end-to-end result is wrong, you want to know immediately which half caused it.

The last is escalation overload. If a large share of cases lands in the human queue, the thresholds or the extraction quality need work. A review queue nobody can keep up with turns into rubber-stamping, which is worse than no review. The production guide to LLM integration covers monitoring and rollout in more detail.

How D3X Solutions LABS helps

We start by mapping the decision itself: the inputs, who makes the call today, and whether the policy is written down or lives in someone’s head. Most of the design work is splitting that process cleanly into interpretation and decision. One half becomes an output schema for the model; the other becomes a rule set your operations team can read.

From there we build the extraction step, the validation and verification layer, and the deterministic gates in front of any action. We assemble a golden set from your historical cases and run the system in shadow mode next to the current process until the numbers justify letting it act. Rules are handed over as tested code or reviewed configuration, with the decision trace logged, so your team can change a threshold without touching a prompt and answer an auditor’s why without guessing.

If you have a decision process that currently depends on someone reading free text and applying policy by hand, book a free 30-minute call using the form below. We will work through where the model should sit and where the rules should.

Frequently Asked Questions

Can an LLM replace a rules engine?

Not for decisions that must be consistent, auditable or legally defensible. An LLM is good at interpreting unstructured input, but its outputs can vary between runs and model versions, and it cannot reliably explain why it decided something. Use the model to produce structured inputs and keep the actual decision in deterministic rules.

How do you validate LLM output against business rules?

Define a strict output schema with types and enums, and reject anything that fails it. Then verify extracted identifiers and amounts against your systems of record, check cross-field consistency such as net plus VAT equalling gross, and apply policy rules in code. Anything that fails validation is retried once or escalated to a person.

What are deterministic guardrails for LLMs?

They are checks enforced in code, outside the model, that an LLM's output or action must pass before it takes effect. Typical examples are spending limits, allow-lists of permitted operations, idempotency keys on payments and mandatory approval above a threshold. They hold regardless of what the model says, which makes them robust to errors and prompt injection.

Should business rules go in the prompt?

You can describe policy in the prompt to improve the model's proposals, but it should never be the enforcement mechanism. Prompt instructions are advisory and can be overridden by unusual or malicious input. The real limits belong in tested, version-controlled code or configuration.

What happens when the LLM and the rules disagree?

Treat disagreement as a signal, not an error to suppress. If the model proposes something the rules reject, either feed the validation error back for a bounded retry or route the case to a human with both the proposal and the failing rule attached. Persistent disagreement on a category of cases usually means the extraction or the policy needs revisiting.

Does a hybrid design help with GDPR rules on automated decisions?

It helps, but it does not settle the question by itself. Explicit rules and a full decision trace make it much easier to explain how a decision was reached and to offer meaningful human review. Whether a given flow counts as a solely automated decision with significant effects is a legal question to confirm with your data protection adviser.

Want this working in your business?

D3X Solutions LABS builds AI agents and automation that pay back fast. Set up a free 30-minute call and we will map your first win together.

Get in touch

Blog

What We Do

Product

Consumer and enterprise software, built with taste and shipped fast.

Infrastructure

AI agents, automation, and orchestration - production systems, not demos.

Advisory

Hands-on engineering and strategy for teams shipping AI into production.