Skip to content

AI Code Quality in Regulated Industries

Most AI code quality advice fails in regulated industries. After consulting for fintech, healthtech, and automotive, here's the framework that passed 11 regulatory audits.

12 min read
Illustrative meticulously assembled small engineering component protected inside a clear glass archival case, with a subtle plain teal tamper-evident seal and a structured tray of unmarked verification samples.
On this page

I spent 6 months consulting for a fintech company that needed to use AI coding tools while staying compliant with SOC 2, PCI DSS, and their banking regulator's software development guidelines. Then I did similar work for a healthtech company under HIPAA. And then an automotive software team working under ISO 26262.

Here's what I learned: most advice about AI code quality is written for consumer SaaS companies. It falls apart the second you add regulatory requirements. The rules change completely when an auditor can ask "who wrote this code and how was it validated?"

The Contrarian Take on AI in Regulated Environments

The common wisdom says regulated industries should move slowly with AI coding tools. Some say they should avoid them entirely. I think that's backwards. Regulated industries should adopt AI coding tools faster than unregulated ones, but with a fundamentally different framework.

Why? Because regulated industries already have the quality infrastructure that makes AI adoption safe. They have mandatory code reviews, automated testing requirements, audit trails, and change management processes. The foundation is already there. They just need to extend it for AI-generated code.

The companies I've seen fail aren't the ones that adopted AI. They're the ones that adopted AI and treated it like human-written code in their compliance documentation. That's the mistake that gets you in trouble.

What Regulators Actually Care About

I've sat through 11 regulatory audits involving AI-generated code. Here's what auditors actually ask:

  1. Provenance: Can you demonstrate who authored each piece of code and how it was generated?
  2. Validation: What testing and review processes verified the code's correctness?
  3. Traceability: Can you trace from a requirement to the code that implements it to the test that validates it?
  4. Change control: Is every code change tracked, approved, and documented?
  5. Risk assessment: Were risks introduced by the generation method identified and mitigated?

These questions focus on control, testing and documentation. The requirements for a particular system still depend on its regulatory and contractual context, including any rules about the tools or development methods used.

The Regulated AI Code Quality Framework (RACQF)

Evidence for the reviewProvenanceReviewTestingAudit trailRisk classification
Figure 1. The framework groups the records used to review an AI-assisted change.

Here's the framework I built across those 3 engagements. It maps to SOC 2, PCI DSS, HIPAA, and ISO 26262 requirements, though you'll need to adapt specifics for your regulatory context.

Pillar 1: Provenance Tracking

The provenance policy below records AI assistance explicitly. Whether a particular annotation is required depends on the applicable standard, contract and assessment scope.

typescript
// .cursorrules or AI tool configuration
// All AI-generated code must include origin annotation

// Option A: Git trailer in commit messages
// AI-Generated: yes
// AI-Tool: cursor/claude-3.5
// AI-Prompt-Hash: sha256:abc123...

// Option B: Code comment annotation
// @ai-generated tool=copilot model=gpt-4 date=2026-03-15
// @ai-reviewed-by vaibhav.verma date=2026-03-16
export function processPayment(input: PaymentInput): Result<Payment, PaymentError> {
  // ... implementation
}

I recommend Option A (git trailers) because it doesn't clutter the code and it's searchable via git log. The hook below checks staged annotations and requires a matching trailer. It cannot discover unannotated AI assistance, so the team still needs an agreed provenance process:[1]

bash
#!/usr/bin/env bash
# .git/hooks/commit-msg
# Require a trailer when an annotation exists in staged content.
set -eu

has_ai_annotation=false
while IFS= read -r -d '' file; do
  if git show ":$file" | grep -q "@ai-generated"; then
    has_ai_annotation=true
    break
  fi
done < <(git diff --cached --name-only --diff-filter=ACMR -z)

if [ "$has_ai_annotation" = true ] &&
   ! grep -Eq '^AI-Generated:[[:space:]]*yes[[:space:]]*$' "$1"; then
  echo "ERROR: Staged annotation requires an AI-Generated: yes trailer"
  exit 1
fi

Pillar 2: Enhanced Review Requirements

In regulated environments, AI code review can't be a casual glance. You need documented evidence of review that maps to specific quality criteria.[2]

The Regulatory Review Checklist:

markdown
## AI Code Review Record

- [ ] Reviewer: _______________
- [ ] Date: _______________
- [ ] AI Tool Used: _______________

### Functional Verification
- [ ] Code implements all requirements in ticket [LINK]
- [ ] All acceptance criteria verified
- [ ] Edge cases identified and handled

### Security Review
- [ ] Authentication/authorization checks present
- [ ] Input validation for all external data
- [ ] No hardcoded credentials or secrets
- [ ] Sensitive data handling follows data classification policy
- [ ] SQL injection / XSS protections verified

### Compliance-Specific
- [ ] PII handling follows data retention policy
- [ ] Audit logging present for state changes
- [ ] Access control follows least-privilege principle
- [ ] Error messages don't expose sensitive information

### AI-Specific Checks
- [ ] Code matches codebase architecture patterns
- [ ] No unauthorized dependencies introduced
- [ ] Error handling follows established pattern
- [ ] AI provenance annotation present

### Sign-off
- [ ] Reviewer certifies code meets quality standards
- Signature: _______________

This checklist becomes an audit artifact. When the auditor asks "how was this code reviewed?" you hand them the completed checklist for every AI-generated PR. I've seen this single document satisfy review requirements for SOC 2, HIPAA, and PCI DSS audits.

Pillar 3: Testing Requirements for AI Code

Regulated industries typically require demonstrable test coverage. For AI-generated code, I enforce stricter standards than human-written code. That might sound unfair, but the rationale is solid: AI code has a higher defect density in edge cases, so it needs more edge case testing.

Proposed team testing targets for AI-generated code:

Test Type Human Code Requirement AI Code Requirement
Unit test coverage 80% line coverage 90% line + branch coverage
Integration tests Happy path + 1 error path Happy path + all error paths
Security tests Standard OWASP checks OWASP + AI-specific checks
Input validation tests Boundary values Boundary + fuzzing
Regression tests For bug fixes For all AI code changes
typescript
// Example: AI-generated payment function with regulated testing

// The function
export function calculateFees(
  amount: number,
  currency: string,
  merchantCategory: string
): Result<FeeBreakdown, FeeError> {
  // AI-generated implementation
}

// Required test suite (MUST cover all these cases)
describe("calculateFees - AI Generated", () => {
  // Happy paths
  it("calculates standard fees for USD domestic transaction");
  it("calculates cross-border fees for non-USD currency");
  it("applies category-specific rate for high-risk merchants");

  // Boundary values
  it("handles minimum transaction amount of 0.01");
  it("handles maximum transaction amount of 999999.99");
  it("rejects zero amount");
  it("rejects negative amount");

  // Edge cases
  it("handles unsupported currency with specific error");
  it("handles unknown merchant category with default rate");
  it("maintains precision for fractional cent calculations");
  it("handles concurrent fee calculations without state leakage");

  // Regulatory requirements
  it("includes regulatory surcharge for applicable states");
  it("caps fees at regulatory maximum for debit transactions");
  it("generates audit log entry for every calculation");
});

Pillar 4: Audit Trail Automation

Manual audit trail maintenance is expensive and error-prone. Automate it.

typescript
// scripts/generate-audit-report.ts
interface AICodeAuditEntry {
  commitHash: string;
  date: string;
  aiTool: string;
  files: string[];
  reviewer: string;
  reviewDate: string;
  testCoverage: number;
  securityScanResult: "pass" | "fail";
  complianceChecklist: string; // URL to completed checklist
}

async function generateAuditReport(
  startDate: Date,
  endDate: Date
): Promise<AICodeAuditEntry[]> {
  // Parse git log for AI-Generated trailers
  // Match with PR review records
  // Pull test coverage from CI
  // Pull security scan results
  // Generate formatted report for auditors
}

Run this monthly. When audit season comes, you hand the auditor a complete report instead of scrambling to reconstruct months of activity.

Pillar 5: Risk Classification

Review follows system riskPayment processingBusiness logicAPI endpointsInternal tools
Figure 2. The article’s risk table assigns review depth according to what the code touches.

Not all AI-generated code carries equal risk. I use a classification system that determines the level of scrutiny each piece of code receives:

Risk Level Code Type Review Requirement Test Requirement
Critical Payment processing, auth, PII handling 2 reviewers + security review 95% coverage + pen test
High Business logic, data transformations 1 senior reviewer + security scan 90% coverage + integration
Medium API endpoints, UI logic 1 reviewer + automated checks 80% coverage + unit tests
Low Internal tools, admin pages 1 reviewer 70% coverage

The classification is based on what the code touches, not how it was generated. AI-generated code that handles credit card numbers gets Critical classification regardless of how simple the function is.

What Changes for Each Regulation

SOC 2

Focus on: change management documentation, access controls, monitoring. AI-specific: document AI tool access as a "logical access" control. Include AI tools in your vendor risk assessment.

PCI DSS

PCI DSS Requirement 6 covers secure development and maintenance of systems and software. Apply the relevant secure-development, review and change-control requirements to in-scope software, and agree the treatment of AI assistance with the assessor.[3]

HIPAA

The HIPAA Security Rule addresses risk analysis, access controls and audit controls for electronic protected health information. Assess any AI service that handles ePHI, including its permitted use, safeguards and any required business associate agreement. Choose logging controls through the system’s risk analysis.[4]

ISO 26262 (Automotive)

ISO 26262-6 covers product development at the software level for safety-related automotive systems. Determine the applicable verification methods, independence and tool-confidence requirements from the licensed standard and the project’s safety plan. The public abstract establishes scope, but does not substantiate the specific ASIL C/D claims made here.[5]

The ROI Argument

Implementing this framework costs 3-4 weeks of engineering time upfront. The return:

  • 60% reduction in audit preparation time (automation)
  • 40% faster regulatory reviews (complete documentation)
  • 0 compliance findings related to AI-generated code across 11 audits
  • Teams still get 50-60% of the AI productivity benefit

The teams that skip this framework don't save time. They spend it differently: scrambling before audits, remediating compliance findings, and explaining to regulators why their AI code wasn't properly controlled.

Getting Started

If you're in a regulated industry and considering AI coding tools, start here:

  1. Week 1: Set up provenance tracking (git trailers + commit hooks)
  2. Week 2: Create the regulatory review checklist and train the team
  3. Week 3: Implement risk classification for your codebase
  4. Week 4: Build the audit trail automation

After the proposed rollout, assess the framework against the applicable obligations and retain evidence that its controls operate. The schedule describes an implementation plan. Compliance and audit readiness require a separate assessment of the actual system.

Frequently asked questions

Are the article’s coverage targets regulatory requirements?

The percentages in the testing and risk tables are proposed engineering policies. Determine the applicable obligations and assurance needs for the system before choosing targets or presenting them as audit evidence.

Do Git trailers establish compliance by themselves?

Trailers can record an AI tool and a reviewer, but they are one part of the evidence trail. Connect them to approved changes, testing results, requirements and the controls relevant to the system being assessed.

Can this framework guarantee a successful audit?

An audit depends on the applicable obligations, assessment scope and evidence that controls operate. Use the framework to organise that evidence and have the responsible compliance or safety team assess the remaining work.

What determines how much review an AI change receives?

Consider the data and operations the change touches, including payments, authentication and protected health information. Use that risk assessment to choose reviewers, test depth and the evidence retained for the change.

Sources

  1. [1]githooks · Git
  2. [2]Secure Software Development Framework (SSDF) Version 1.1: Recommendations for Mitigating the Risk of Software Vulnerabilities · NIST
  3. [3]PCI DSS v4: What’s New with Self-Assessment Questionnaires · PCI Security Standards Council
  4. [4]Summary of the HIPAA Security Rule · US Department of Health and Human Services
  5. [5]ISO 26262-6:2018 · ISO

Checked against these sources on

Related Articles