A typical PCI DSS audit preparation looks like this: a spreadsheet with hundreds of rows, each with a requirement, an owner, a link to the "evidence" and a status. Half the links point to cloud console screenshots taken six months ago. A couple of weeks before the QSA visit, the team drops product work and rebuilds the evidence from scratch, because the infrastructure has changed in the meantime.
With PCI DSS v4.0.1, the version in force today, this approach stopped working even as a bad one. Below: how to replace the spreadsheet with a system of agents, where it actually saves time, and where an LLM must never get near card data.
01The end of manual compliance
v3.2.1 was retired on 31 March 2024, and v4.0 on 31 December 2024: assessments now run against v4.0.1, a limited revision that clarifies the text and adds no new requirements. From 31 March 2025, the requirements v4.0 introduced as best practice became mandatory too (51 of the 64 new ones). Three changes matter for an engineering team.
- Compliance became continuous. Requirement 12.5.2 asks you to confirm scope at least every 12 months and after every significant change; for service providers, every 6 months under 12.5.2.1. In a company that deploys ten times a day, a "significant change" happens all the time.
- Frequencies now need a justification. Where the standard allows a flexible frequency, it asks for a targeted risk analysis (12.3.1). That is a document to keep current, not to write once.
- Some requirements cannot be met by hand at all. 6.4.3 and 11.6.1: inventory and change detection for scripts on the payment page. 10.4.1.1: automated log review. A person with a spreadsheet will not keep up.
Compliance became continuous
Three dates, then a duty with no end date: confirm scope on a schedule and after every significant change.
- 31 Mar 2024
v3.2.1 retired
- 31 Dec 2024
v4.0 retired, v4.0.1 in force
A limited revision: clarifications, no new requirements.
- 31 Mar 2025
Future-dated requirements mandatory
51 of the 64 requirements new in v4.0 move from best practice to mandatory.
- After that · continuous
- 12.5.2Scope reconfirmed every 12 months
- 12.5.2.1Every 6 months for service providers
- 12.5.2And after every significant change
Hence AIaaS for compliance. Not "a neural network that passes the audit for you", but a set of agents that run as a service inside your perimeter: they keep reading infrastructure, code and documents, match them against the requirements, and file evidence where an assessor will look for it. The QSA still decides on compliance. The agents remove the manual work that comes before that decision.
02A multi-agent architecture: who does what
One big "check PCI" agent does not work: the context sprawls and the answers cannot be checked. A working setup is built from narrow roles with explicit inputs and outputs.
Agents exchange facts, not conclusions
Narrow roles with explicit inputs and outputs, all ending in one evidence store.
Policy RAG. Indexes the standard (v4.0.1, including the Testing Procedures and Guidance), your policies and procedures, and past ROCs and AOCs. It answers questions like "what did we promise about key rotation" with a reference to the paragraph. One detail matters: chunk by requirement number, not by token count. Otherwise 3.6.1.2 gets glued to 3.6.1.3 and the agent quotes the wrong requirement.
Infra Scanner. Works only through read-only roles and only through APIs: security groups, NACLs, VPC peering, IAM policies, KMS key state, CloudTrail settings, Terraform state. Its output is normalised facts, not prose conclusions: {resource, property, value, observed_at}.
Code & Change Agent. Looks at every pull request that touches the CDE or the scope boundary: Terraform, Helm, database migrations, code where card data fields appear.
QSA Simulator. The orchestrator. It takes the standard's testing procedures ("examine configurations", "interview personnel", "observe processes") and decides, for each one, which facts are enough, which are missing, and where a person is needed. The model does not invent compliance here. It matches the scanners' facts against the wording of the procedure and states exactly what is missing.
The rule the whole setup depends on: agents exchange facts with references, not conclusions. Every statement in the report points to a specific object in the Evidence Store. A statement without a reference does not make it into the report.
Agents exchange facts with references, not conclusions. A statement without a reference does not make it into the report.
03Method: four steps to continuous compliance
From a yearly scramble to a continuous loop
Each step runs on its own trigger instead of once before the audit.
- 1
Automated scoping
The connectivity graph is recomputed on every network change.
- 2
Gap analysis in CI/CD
High findings block the merge; the rest go to the backlog.
- 3
Continuous evidence
Scanners snapshot the state on a schedule, stored under WORM.
- 4
Audit rehearsal
Once a sprint, the QSA Simulator produces a gap report.
- network change
- merge request
- schedule
- sprint
Step 1. Automated scoping. The Infra Scanner builds a connectivity graph: which segments can reach the systems that store, process or transmit PAN. Anything connected to the CDE becomes connected-to and lands in scope. The graph is recomputed on every network change, not once a year. The result is what 12.5.2 asks for, a documented and confirmed scope, except it is confirmed continuously.
Step 2. Gap analysis in CI/CD. The Code & Change Agent sits in the pipeline as an ordinary check:
pci-gate:
stage: test
rules:
- changes: [infra/**, services/payments/**, db/migrations/**]
script:
- pci-agent diff --base "$CI_MERGE_REQUEST_DIFF_BASE_SHA" --scope cde.graph.json
- pci-agent report --fail-on highIt does not need to understand the whole standard. It answers narrow questions: does this change open a new path into the CDE? Has a field that looks like PAN appeared outside the vault? Does the change switch off logging or encryption? High findings block the merge; the rest go to the backlog with a requirement number.
Step 3. Continuous evidence collection. Instead of screenshots taken the night before the audit, scanners snapshot the state on a schedule and store it with a WORM policy (S3 Object Lock, for example), a hash and a timestamp. The assessor gets an immutable snapshot of the configuration on a given date and its change history, not "a console screenshot".
Step 4. Audit rehearsal. Once a sprint, the QSA Simulator runs the testing procedures across all 12 requirement areas and produces a gap report. It does not replace the QSA. It is a way to arrive at the real audit without surprises.
04Case 1: greenfield
A new fintech with a payments product and no code yet. There are architecture diagrams and Terraform skeletons. This is the best moment for compliance by design: scope is cheapest to shrink before it exists.
What it looks like in practice:
- Checking the architecture before the code. The architect describes the data flows: where PAN comes in, where it is tokenized, who calls detokenization. The agents check the description against requirements 1, 3 and 4 and ask the awkward questions: "The notification service receives the whole transaction object. Does it carry PAN?"
- A minimal CDE. The target: PAN reaches only an isolated tokenization service (hosted fields or the provider's iframe on the front end, a separate VPC, a separate cloud account). Everything else works with tokens and stays out of scope, or connected-to.
- Policy as code from the first commit. Rules like "no public buckets in the CDE account" or "no egress from the CDE except to an allowlist of processors" live as OPA or Checkov policies and run on every
terraform plan.
Keep the CDE small before it exists
PAN reaches only an isolated tokenization service. Everything else works with tokens.
The main gain here is not speed. Contentious architecture decisions surface at the diagram stage, not at the ROC stage.
05Case 2: brownfield, breaking up the legacy
This is the case the whole thing is for. The typical picture: a monolith more than ten years old, one Oracle or Postgres database with thousands of tables, and nobody can say for certain where the card numbers are. So the whole system is in scope.
Finding card data. The classic approach is a regex for 13 to 19 digits plus a Luhn check. On a legacy database it produces thousands of false positives (contract numbers, phone numbers, identifiers) and misses the most dangerous cases. So the search is built in three layers.
- A deterministic pre-filter, no LLM. Sample every text and numeric column, run the regex and Luhn, and check the first 6 to 8 digits against BIN/IIN ranges. PAN is also searched for in the less obvious places: free text (
comments,notes), JSON and XML in blob fields, base64, application logs,*_bakand*_oldtables, URLs in access logs. - Contextual classification. This is where a model comes in, but it receives metadata, not values: the table and column names, the neighbouring columns, types, foreign keys, the pre-filter's hit rate, and a masked sample like
4111 11** **** 1111. The question to the model: is this PAN, truncated PAN, a token, or noise? Acard_no,exp_month,holder_nametrio in one table almost always means live data. Aref_numbercolumn with a 3% Luhn hit rate almost certainly does not. - A lineage graph. Foreign keys, triggers, stored procedures and ETL code show where the data came from and where it goes. That is the map of what will have to be rewritten.
Three layers, and the model only sees metadata
A deterministic pre-filter, then a model that sees names and masked samples, then lineage.
-- candidates to review: columns where over 30% of samples pass Luhn
SELECT table_name, column_name, luhn_hit_ratio, bin_match_ratio
FROM pci_discovery.column_stats
WHERE luhn_hit_ratio > 0.3
ORDER BY bin_match_ratio DESC;Moving into an isolated vault. Then the strangler pattern:
- Stand up an isolated vault: a separate account or segment, its own database, a
tokenize/detokenizeAPI, and detokenization open only to a short list of services (usually the outbound call to the processor). - New records are written through the vault: the monolith receives a token instead of PAN (dual-write for the transition).
- Backfill: historical PAN moves into the vault in batches and is replaced by tokens in the source table. Every batch is reconciled by count and hash.
- The agents repeat discovery across the whole database, the logs and the backups. Scope shrinks only when the repeat scan finds nothing. Backups holding PAN stay in scope until their retention runs out, and they are often forgotten.
Scope shrinks only when the re-scan finds nothing
Vault first, then dual-write, then backfill in batches, then a repeat scan.
Keys: CloudHSM or an on-premise HSM. The vault stores PAN encrypted, and requirements 3.6 and 3.7 on key management still apply. The choice usually looks like this.
| Cloud (AWS CloudHSM / KMS) | On-premise HSM (Thales, Utimaco and others) | |
|---|---|---|
| Certification | CloudHSM: dedicated HSMs validated to FIPS 140 Level 3; KMS: a multi-tenant service | FIPS 140 Level 3, often PCI PTS HSM |
| Control | Your keys; the provider's hardware and operations | Full, including physical access |
| Operations | Cluster, backups and HA out of the box | Your own data centres, key ceremonies, redundancy, people |
| When to choose it | The workload is already in the cloud; no regulator requirement to keep keys on site | A regulator requirement, hybrid with processing, your own issuing |
A practical compromise is envelope encryption. Data keys encrypt the records in the vault, and the master key lives in the HSM. Rotating the master key does not require re-encrypting the whole database, and a compromised data key is confined to its segment.
Envelope encryption: rotate one key, not the database
The master key stays in the HSM and wraps the data keys that encrypt the vault.
06Limits: the security of the models themselves
The question every CISO asks first: "Are you proposing to show our CDE to a neural network?" No, and that has to be guaranteed technically, not by policy.
- PAN never reaches the model. Every LLM call sits behind a DLP filter (the same regex, Luhn and BIN check) that masks or blocks the request. In the setup from section 5, the model gets metadata and masked samples, not values.
- External models only with zero data retention. If a cloud API is used, you need a zero-retention agreement, or a deployment in your own cloud account where the provider neither stores prompts nor trains on them. That belongs in the contract, not in a setting.
- Local models for anything inside the CDE. An open-weight model on your own GPUs inside the segment. Classifying columns and reading configs does not need a large model.
- Agents only read. Scanners have read-only roles; remediation is done by a person or by an ordinary pipeline after review. An agent with write access to the CDE becomes part of the scope itself, and a new attack surface.
- Prompt injection from documents. The agent reads policies, tickets and code comments, any of which may contain "ignore the previous instructions". Agent output is validated against a schema, and a conclusion without a reference to a fact is discarded.
- The model is not the source of truth. An agent's output is a hypothesis with references. The evidence for the QSA is the configuration snapshot, not the text a model wrote.
PAN never reaches the model
A DLP filter in front of the model, a schema check behind it, read-only roles throughout.
07Where to start
Do not start with the CDE. Start with the paperwork, where there is no risk and the most pain.
- 01
One index
Put the PCI DSS v4.0.1 standard, your policies and procedures, and the last ROC into one index. - 02
One RAG agent
Stand up one RAG agent, chunked by requirement number, and ask it: "For every requirement, show which of our documents covers it and where our document contradicts the standard." - 03
Review together
Review the result with whoever prepares the audit. This step alone usually turns up outdated procedures, v4.0.1 requirements with no owner, and policies that contradict each other.
The next step adds a read-only infrastructure scanner and the CI check. Discovery on the legacy database is best left until the first agents have proven their accuracy on safe data.
If you are in the middle of the move to v4.0.1, or taking apart a monolith with card data inside, talk to us. We will compare your current audit preparation with this setup and show which agent to start with.