← Back to Blog

Deterministic Checks First, LLM Last: Inverting the Compliance Verification Pipeline

November 13, 2026 · 7 min read
Deterministic Checks First, LLM Last: Inverting the Compliance Verification Pipeline - Why asking LLMs to judge numerical limits causes hallucinations, and how combining deterministic gates with semantic meaning checks creates audit-ready AI.

A team building a regulatory compliance assistant for imported consumer goods designs what seems like an elegant prompt:

You are an expert EU regulatory auditor. 
Review the following ingredient list, technical specification, and marketing claims.
Determine whether the formulation complies with EU Regulation EC 1333/2008 and consumer disclosure directives.
Output JSON: {"compliant": true/false, "violations": [...]}

During testing on twenty standard product labels, the system performs cleanly. The marketing deck advertises automated regulatory verification.

Three weeks into production, a batch of imported confectionery containing Titanium Dioxide (E171) clears the automated checkpoint. The model outputs compliant: true, accompanied by a polished explanation stating that the additive is permitted under historical food additive schedules.

The problem: Titanium Dioxide was fully banned for food use across the European Union in 2022 under Regulation (EU) 2022/63.

The model did not make a mathematical calculation or check an official statutory database. It sampled tokens from a probability distribution shaped by fifteen years of pre-2022 internet text where E171 was mentioned as a standard food coloring thousands of times.

Asking a probabilistic model to enforce hard statutory boundaries is an architectural mistake. But stripping the model of judgment entirely is equally short-sighted.

The real engineering challenge is knowing where deterministic code must rule, and where the language model’s semantic reasoning is irreplaceable.


The Misguided Extremes: The Judge vs The Formatter

Teams tackling compliance automation usually swing between two flawed extremes.

The first extreme is the LLM as Judge: tossing unstructured documents into a prompt and trusting the model to evaluate binary thresholds, banned lists, and dates. This fails because probabilistic models do not execute inequalities or database joins; they generate statistically likely completions. A model asked to verify whether sulfur dioxide exceeds 10 mg/kg routinely confuses unit conversions, jurisdiction boundaries, or outdated amendments.

The second extreme is the LLM as Formatter: reducing the language model to an expensive template engine that only formats pre-computed SQL queries. If an architecture only needs to print SELECT * FROM banned_substances, a lightweight templating library handles that with zero latency and zero GPU cost.

The actual difficulty in enterprise compliance is that real regulations are divided into two distinct layers:

  1. Hard statutory boundaries (banned lists, numerical concentration ceilings, statutory deadlines, schema validity).
  2. Contextual semantic conditions (intended use, marketing claim alignment, functional exemption clauses, ambiguous contractual indemnity).

Deterministic code thrives on the first layer and is blind to the second. The language model thrives on the second layer and hallucinates on the first.


The Inverted Architecture: Hard Gates First, Semantics Second

In a production compliance pipeline, deterministic code runs first to lock down the non-negotiable boundaries, freeing the LLM to focus on what it does best: the semantic meaning check.

[Raw Incoming Documentation]
             │
             ▼
[Stage 1: Deterministic Pre-Filters & Hard Gates]
├── Schema validation (Pydantic / JSON Schema)
├── Banned substance list checks (Relational SQL)
└── Maximum Permitted Level (MPL) inequalities
             │
             ├── Hard Violation Detected? ──► [Immediate FAIL / Reject]
             │
             ▼ Clean on Hard Bounds
[Stage 2: LLM Semantic Meaning & Context Check]
├── Qualitative intent & intended purpose analysis
├── Consumer claim alignment (EU Green Claims Directive)
└── Contextual exemption & derogation evaluation
             │
             ▼
[Stage 3: Deterministic Grounding & Citation Validation]
├── Verbatim citation match against retrieved statutory text
└── Confidence gating & refusal threshold
             │
             ▼
[Audit-Ready Compliant Output]

Stage 1: Deterministic Hard Gates

Before an LLM spends a single token of reasoning, deterministic code enforces the binary rules of law.

If a formulation contains a substance banned under EU Annex II, or if a reported concentration violates a hard numerical threshold, the pipeline halts immediately:

from pydantic import BaseModel, Field
from typing import List

class IngredientEntry(BaseModel):
    name: str
    e_number: str | None = Field(default=None, pattern=r"^E\d{3,4}[a-z]?$")
    concentration_mg_kg: float | None = None
    functional_use: str | None = None  # e.g., "carrier", "preservative", "emulsifier"

def evaluate_hard_boundaries(ingredients: List[IngredientEntry], statutory_db):
    for item in ingredients:
        # Deterministic absolute ban check
        if item.e_number and statutory_db.is_banned(item.e_number):
            return {"verdict": "FAIL", "reason": f"{item.e_number} is strictly banned."}
            
        # Deterministic numerical ceiling check
        if item.e_number and item.concentration_mg_kg:
            mpl = statutory_db.get_mpl(item.e_number)
            if mpl and item.concentration_mg_kg > mpl:
                return {"verdict": "FAIL", "reason": f"Exceeds MPL of {mpl} mg/kg."}
                
    return {"verdict": "PASS_TO_SEMANTIC_STAGE"}

No prompt injection, persuasive phrasing, or hallucinated legal history can bypass this gate. The absolute boundaries are locked in code.


Stage 2: The LLM Semantic Meaning Check

Once the hard boundaries pass, the document enters the nuanced territory that SQL queries cannot resolve: contextual interpretation.

Consider EU food and consumer safety law:

  • Functional Use Classification: An additive might be restricted as a surface preservative, but permitted as a processing aid or manufacturing carrier. Determining whether a substance serves as an active preservative or a carrier requires parsing the manufacturing process description.
  • Consumer Claim Alignment: If the package claims “100% Clean Label” or “All-Natural Bio-Extract”, but the formulation relies on synthetic processing solvents, is the claim misleading under the EU Green Claims Directive?
  • Statutory Derogations: Does a specific product classification qualify for a localized cultural or industrial exemption defined in an explanatory memorandum?

This is where the LLM performs the meaning check:

def evaluate_semantic_compliance(client, product_dossier, retrieved_statutory_context):
    prompt = f"""
    The formulation has passed all deterministic banned-list and numerical threshold checks.
    
    Your task is to conduct the SEMANTIC and CONTEXTUAL review:
    1. Evaluate whether the stated 'functional_use' of each ingredient genuinely matches
       the manufacturing process described in Section 4.
    2. Assess whether packaging claims (e.g. 'Pure Plant Formula') are semantically misleading
       under the retrieved consumer transparency directives.
    3. Determine whether any contextual derogations claimed by the supplier legally apply
       to this specific product category.
       
    Retrieved Legal Standards:
    {retrieved_statutory_context}
    
    Product Dossier:
    {product_dossier}
    
    Require every finding to cite specific verbatim excerpts from the statutory context.
    """
    
    return client.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": prompt}],
        temperature=0.0
    )

The language model does not guess whether numbers are greater than other numbers. It uses its language comprehension to evaluate intent, nuance, and contextual alignment against retrieved legal ground truth.


Stage 3: Deterministic Grounding & Output Validation

The final stage ensures the model’s semantic reasoning remains grounded in verified facts.

A deterministic post-processor verifies that:

  1. Every legal citation in the model’s semantic evaluation matches an actual string in the retrieved statutory corpus.
  2. The model did not contradict any Stage 1 deterministic pass/fail flags.
  3. If the model flags ambiguity or low semantic certainty, the case routes to a human auditor rather than silently guessing.

The Audit Defense Under the AI Act

Under Article 14 (Human Oversight) and Article 15 (Accuracy and Robustness) of the EU AI Act, regulators scrutinize automated systems in high-risk domains.

An architecture that relies solely on an LLM to judge compliance fails an audit because its decision boundary is opaque and non-deterministic. An architecture that uses no AI fails in the real world because static rules collapse under contextual nuance.

A hybrid pipeline that enforces hard statutory boundaries deterministically, applies language models to evaluate semantic meaning, and bounds the output with deterministic citation gates delivers both mathematical rigor and contextual intelligence.

Deterministic code sets the boundary. The model evaluates the meaning.


In your current compliance pipelines, where do you draw the dividing line between what code evaluates deterministically and what you trust an LLM to interpret semantically?

Have a project in mind?

Let's talk about how we can help.

Got a project idea? →