Cruxly

Cruxly › AI engineering › Reliability, Security & Governance

Red-Teaming and Compliance as Code

the OWASP LLM Top 10, adversarial testing, and DPDP erasure that actually erases

Open the interactive lesson

Prompt: design the security and compliance layer for a production AI system handling personal data: an adversarial testing suite covering the OWASP LLM Top 10, run in CI on every change, and a data-protection implementation where a user's right-to-erasure request is a code path, not a policy promise.

40 minutes first. "We reviewed it and it seemed safe" is not a security program. Neither is "we have a privacy policy" a compliance program.

The OWASP LLM Top 10, and what a standard pentest misses

Use the current list and its current names — quoting an old edition is an easy tell. The current one is the 2026 edition, published on 4 August 2026 (the project's GenAI-LLM-Top10 repository, 2026/final, is the canonical text). Prompt injection is still the headline item, but a traditional web pentest checks for almost none of the other nine:

#2026 category2025 positionWhat it means for this system
LLM01Prompt InjectionLLM01Direct and indirect (via retrieved docs, tool results)
LLM02Sensitive Information DisclosureLLM02The model reveals data the user isn't allowed to see
LLM03Excessive AgencyLLM06 ↑More tools, permissions or autonomy than the task needs
LLM04Supply ChainLLM03Compromised models, adapters, datasets, plugins
LLM05Data and Model PoisoningLLM04Fine-tuning or RAG data planted to change behaviour
LLM06Unbounded ConsumptionLLM10 ↑Cost and denial-of-service through unlimited token use
LLM07MisinformationLLM09Confident wrong answers users act on
LLM08Hidden Context ExposureLLM07 (renamed)Anything the app puts in front of the model that the user can't see — system prompt, retrieved docs, tool results, memory — extracted
LLM09Vector and Embedding WeaknessesLLM08Cross-tenant retrieval leaks, embedding inversion — directly relevant to the RAG modules
LLM10Improper Output HandlingLLM05 ↓Model output executed or rendered unsanitised

:::key Verified October 2026 The ten entries and their order match the 2026/final folder of the OWASP GenAI-LLM-Top10 repository on GitHub, read 31 October 2026 (README: published, released 4 August 2026). The 2025 column is the previous edition's numbering. Check genai.owasp.org before citing, since later revisions are possible. :::

What the reshuffle tells you. Eight of the ten moved, and the 2026 ranking weighted practitioner votes at 75% and a record of 6,639 classified incidents at 25%, so real incident data moved some entries. Two moves are worth saying out loud:

Positions changing doesn't mean a risk got less dangerous — Improper Output Handling dropping to 10th still means "never execute or render model output unsanitised."

OWASP has also published a separate Top 10 for agentic applications — worth naming for any system where the model calls tools.

Poisoning is cheaper than intuition says. A 2025 study (Anthropic with the UK AI Security Institute and the Alan Turing Institute) found that a small, roughly constant number of poisoned documents — on the order of a few hundred — could implant a backdoor regardless of model size. "Our dataset is huge, a few bad documents won't matter" is not a defence.

Run a regression suite covering every category on every change that touches the model, prompt, or tool layer — the same way a traditional security suite runs on every PR. A hand-written set of a few dozen prompts is a seed, not a bar:

Report an attack success rate with its sample size, not a pass/fail. LLM outputs vary, so a vulnerability caught 8 times out of 10 runs is a real vulnerability, not a flaky test to retry until it passes. And "absent across N runs" bounds the rate rather than proving zero: by the rule of three, 0 successes in N tries means the true rate is plausibly up to about 3/N — so 0 in 30 still allows roughly a 10% success rate. Pick N from the risk you can tolerate.

DPDP as code: consent, erasure, and minimisation that actually run

Consent needs to be a structured, queryable record attached to every piece of data collected, not an assumption baked into a signup flow. "The user consented when they signed up" is not sufficient when different processing purposes (analytics, model training, third-party sharing) may each require distinct, revocable consent — the system needs to be able to answer "did this specific user consent to this specific use of this specific data" as a database query, not a policy interpretation.

Right-to-erasure has to reach every store the data touches, including the ones that are easy to forget. A user's data typically lives in a primary database, but for an AI system it may also live in: a vector store (as embeddings derived from their documents or conversations), a cache, a fine-tuning dataset, and application logs. An erasure implementation that deletes from the primary database but forgets the vector store has satisfied the letter of a checklist while completely failing the actual legal requirement, since the embeddings still encode information derived from that person's data.

The store nobody can delete from: a model already trained on the data. Removing a user's rows from the fine-tuning dataset doesn't remove what the weights learned from them, and reliable machine unlearning doesn't exist yet for production models. So the policy has to be decided up front:

Know the actual compliance dates. India's DPDP Rules were notified in mid-November 2025 (sources give 13 or 14 November) with an 18-month phased rollout: the Data Protection Board provisions (Rules 1, 2 and 17 to 21) applied immediately, Consent Manager registration (Rule 4) starts on 13 November 2026, and the substantive obligations (Rules 3, 5 to 16, 22 and 23) apply from 13 May 2027. "DPDP as code" should track those dates. And DPDP's "legitimate uses" (section 7) mean not every processing purpose needs consent; the consent record should note which basis applies to each use.

:::key Verified October 2026 Phase dates as summarised by law-firm and EY write-ups of the Rules, read 31 October 2026: Rules 1, 2 and 17 to 21 immediately; Rule 4 (Consent Managers) on 13 November 2026; Rules 3, 5 to 16, 22 and 23 on 13 May 2027. Sources differ on whether notification was 13 or 14 November 2025, so quote the phase dates and read the Gazette text before relying on them. :::

Data minimisation means designing collection to happen narrowly from the start, not filtering broadly-collected data down later. Collecting everything "in case it's useful" and then relying on access controls to limit exposure is a weaker posture than never collecting what a specific feature doesn't need in the first place — every field collected is a field that has to be secured, minimized, and eventually erased correctly, so the cheapest compliance is not collecting it.

Incident response for an AI-specific incident

A rollback capability needs to cover prompt versions and model versions with the same rigor as code versions. If a prompt change caused a quality or safety regression, "roll back to the previous prompt version" needs to be as fast and as reliable an operation as rolling back a code deploy — which requires versioning prompts as a first-class artifact (with the same review and deployment discipline as code) rather than as strings embedded in application code that happen to change when the code around them changes.

A post-mortem for an AI incident needs to answer a different root-cause question than a traditional outage post-mortem. "The service returned 500s because the database connection pool was exhausted" has a clear, deterministic root cause. "The model started producing inappropriate responses to a specific query pattern" requires investigating whether the cause was a prompt change, a retrieval change surfacing different context, a provider-side model update you didn't initiate, or genuine variance — and the post-mortem process needs to be built to investigate all four possibilities systematically, not stop at the first plausible explanation. The provider-update cause is largely preventable: pin a dated model snapshot instead of a floating alias, so the model only changes when you change it.

Runbook testing for AI incidents needs to be exercised specifically, not assumed to generalize from traditional runbooks. "If the model starts hallucinating at an elevated rate, here's the immediate mitigation (route to a more conservative fallback, tighten the grounding instruction, or disable the affected feature)" needs to be a tested, rehearsed runbook — not a plan that's only ever been discussed hypothetically and gets improvised for the first time during a real incident.

Where compliance and security overlap, and where they pull in different directions

Detailed audit logging (for compliance and incident investigation) and data minimisation (for privacy compliance) are in genuine tension, and resolving it needs an explicit policy, not an accident of what happened to get logged. Logging full request content supports investigation and accountability; logging less supports minimisation and reduces breach exposure. The resolution is usually structured logging with different retention periods and access levels per field — not a single blanket decision to log everything or log nothing.

A security fix and a compliance fix can require different testing before shipping. A prompt-injection patch needs adversarial testing to confirm it closes the specific vulnerability; a consent-tracking change needs testing against real regulatory scenarios (a user requesting erasure mid- processing, a user revoking one consent type while others remain active) that a standard test suite wouldn't naturally cover, and building the compliance test suite requires the same deliberate design effort as the security one, not an assumption that passing normal tests implies compliance.

The honest limitation worth naming to any stakeholder: no red-team suite, however thorough, proves the absence of a vulnerability — it proves the absence of the specific vulnerabilities tested for. Continuous, evolving adversarial testing that incorporates new attack patterns as they're discovered in the field is the realistic goal, not a one-time "secured" checkbox that stays true indefinitely.

The regulatory and frontier-safety landscape you're expected to know

Data protection (DPDP, GDPR) is only one layer. AI-specific regulation and industry safety frameworks now shape what a production system has to do, and a 2026 interview at an AI company will check you know the shape of them.

The EU AI Act — risk-based, with staggered dates. It applies to anyone placing AI systems on the EU market or whose outputs are used in the EU, regardless of where the company sits.

DateWhat applies
Aug 2024Act enters into force
Feb 2025Prohibited practices banned (e.g., social scoring, manipulative techniques); AI-literacy duty
Aug 2025Obligations for general-purpose AI (GPAI) model providers, backed by a Code of Practice
Aug 2026Article 50 transparency duties (AI-interaction disclosure, deepfake labelling) — in force
Dec 2026Two new prohibitions added by the Digital Omnibus (AI-generated non-consensual intimate imagery, and CSAM); end of the grace period for Article 50(2) machine-readable marking of AI-generated content by generative systems already on the market before 2 Aug 2026 (new systems owe it from 2 Aug 2026; confirm scope against Regulation (EU) 2026/1744 in the Official Journal)
Dec 2027Stand-alone high-risk systems (Annex III) — moved from Aug 2026 by the Digital Omnibus
Aug 2028High-risk AI embedded in regulated products (Annex I) — moved from Aug 2027

Voluntary frameworks that buyers and auditors ask about:

How frontier labs govern their own models — worth knowing if you're interviewing at one:

The engineering takeaway: regulation increasingly asks for evidence — evaluations, logs, incident records, documentation — which is exactly what the observability, red-teaming and compliance-as-code practices in this module produce.

How to say it in the interview

"A privacy policy is a promise about what happens. Compliance as code is a guarantee, because the guarantee is enforced by a code path that actually runs - if erasure is a manual process someone has to remember to do across every data store including the vector database, it will eventually be missed, and 'eventually' is not acceptable for a legal right."

Checklist

Practice this interactively
Share this lessonWhatsAppLinkedInX

Related lessons