cd /news/ai-agents/your-ai-agent-followed-the-procedure… · home › topics › ai-agents › article
[ARTICLE · art-180775] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Your AI Agent Followed the Procedure. Which Version?

A developer working on regulated-industry AI agents describes a bitemporal, append-only schema for versioned procedures, using PostgreSQL range types and an exclusion constraint to guarantee that two revisions of the same procedure never overlap in effective dates. Retrieval is keyed to an as-of timestamp taken from the business event rather than the current time, and embeddings are stored per (procedure_id, version, chunk_no) so vector search cannot surface a superseded passage. The approach is framed as a way to satisfy audit-trail expectations under 21 CFR Part 11.10(e) and EU GMP Annex 11, which the developer says most agent backends cannot currently meet.

recommendation

Version controlled documents as append-only bitemporal rows with an exclusion constraint on effective ranges, and filter vector search to the revision in force at the business event's timestamp.

more in playbook: Retrieval and RAG
by read5 min views9 publishedDec 3, 2026

In regulated industries, an agent answer is only defensible if you can prove which rules were in force when it ran.

Draft created: 2026-12-03 | Status: Draft, pending partner review | Vertical alignment (E14): regulated-industry AI SaaS (pharma/life sciences compliance, research-integrity tooling); no Email-2/3 sequences are active this week, so aligned to the 2026-12-03 market intel instead

An agent tells a quality manager that a deviation on a batch record needs escalation, citing the cleaning procedure. Six weeks later an auditor asks which revision of that procedure the agent read, and whether it was the revision in force on the day of the batch. Most teams building agents on top of controlled documents cannot answer. The vector index holds whatever was last embedded, and the answer was never tied to a version.

A typical retrieval pipeline chunks documents, embeds them, and returns the top-k nearest chunks. That works for a wiki. It breaks for SOPs, work instructions and policy documents, because those are versioned, approved, and effective-dated. Revision 7 of a procedure is valid from one date to another, and a record created inside that window must be judged against revision 7 even if revision 9 exists today.

Three failure modes show up repeatedly in agent backends for regulated customers:

Regulators do not prescribe an architecture here, but the expectation is stable. 21 CFR Part 11.10(e) calls for secure, computer-generated, time-stamped audit trails that record actions creating, modifying or deleting electronic records. EU GMP Annex 11 asks for audit trails on computerised systems in the same spirit. An agent that influences a quality decision and leaves no trace of its inputs is a gap in that trail.

The pattern is consistent in lean teams that have just raised and are moving into enterprise sales. The first version of the agent ships fast, usually one or two strong backend engineers plus a framework. It works in the demo. Then the first pharma or medtech security questionnaire arrives and asks about traceability, and the team discovers that provenance was never a first-class concept in the schema.

Retrofitting is expensive because the missing data cannot be backfilled. You cannot reconstruct which chunks a model saw three months ago if you never stored them. That is why this belongs in the first sprint of the data model, before the second customer.

Our recommendation is to treat procedures as bitemporal, append-only data and to store the retrieval set with every run. In PostgreSQL this is a small amount of schema.

CREATE EXTENSION IF NOT EXISTS btree_gist;

CREATE TABLE procedure_version (
  procedure_id  uuid        NOT NULL,
  version       int         NOT NULL,
  content_sha256 text       NOT NULL,
  body          text        NOT NULL,
  effective     tstzrange   NOT NULL,   -- when this revision is in force
  approved_at   timestamptz NOT NULL,   -- when the approval was recorded
  PRIMARY KEY (procedure_id, version),
  EXCLUDE USING gist (procedure_id WITH =, effective WITH &&)
);

The exclusion constraint guarantees that two revisions of the same procedure never overlap in time. The database enforces it, so no application bug can create an ambiguous answer to "what was in force on this date".

Retrieval then takes an as-of timestamp, and that timestamp is the date of the business event, not now().

SELECT procedure_id, version, content_sha256, body
FROM procedure_version
WHERE effective @> :event_time::timestamptz;

Embeddings live in a table keyed by (procedure_id, version, chunk_no). A new revision adds rows and never updates or deletes old ones. Vector search is filtered to the revision set returned above, so the retriever physically cannot surface a superseded passage for a current event, or a current one for a historical event. With pgvector this is an ordinary join or a filtered index scan, and you keep one datastore to back up, validate and explain to a customer's IT security team.

Every agent run then writes one immutable row:

CREATE TABLE agent_run (
  run_id         uuid PRIMARY KEY,
  started_at     timestamptz NOT NULL,
  event_time     timestamptz NOT NULL,
  model_id       text        NOT NULL,   -- exact model identifier as returned by the provider
  prompt_version text        NOT NULL,
  retrieved      jsonb       NOT NULL,   -- [{procedure_id, version, chunk_no, sha256}]
  output         jsonb       NOT NULL
);
REVOKE UPDATE, DELETE ON agent_run FROM app_role;

Three details matter. Store the content hash next to the version number, so a later edit to a row is detectable. Store the model identifier and prompt version, because a provider-side model update changes behavior even when your documents did not change. Revoke update and delete at the database level and add a trigger that rejects them for the table owner role used in migrations, rather than relying on code review.

Add one integration test that replays the audit scenario. Create revision 1, run the agent, publish revision 2, run the agent for a historical event date, and assert that each run's retrieved field points at the right revision. Then pick any run_id and assert you can reconstruct the exact prompt input from stored data alone. If that test passes, a customer questionnaire on traceability becomes a screenshot of a query instead of a two-week engineering project.

Two cautions. First, an exact replay of model output is not guaranteed even at temperature zero, so what you can promise is reconstruction of inputs and a complete record of what the model returned, not bit-identical regeneration. Say that clearly in customer documentation. Second, this design gives you traceability, not validation. A computerised system in a GxP setting still needs its own validation approach agreed with the customer's quality team.

tstzrange, and never update embeddings in place. SifrVentures builds dedicated engineering teams for tech companies. Based in Berlin. Learn how we work | Read more on our blog

── more in #ai-agents 4 stories · sorted by recency
── more on @postgresql 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/your-ai-agent-follow…] indexed:0 read:5min 2026-12-03 · —