Interview's MateAI Engineering
Interview's Mate

AI Engineering

LLMs, RAG, agents & evals

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
AI Engineering topics
Lesson 120/ 160
06. AI Security

Red Teaming

Adversarial testing programs that continuously probe AI systems for safety failures.

AdvancedAdversarial Tests · Coverage3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidHands-onQuiz (3)Practice

In plain words

Red teaming means hiring friendly attackers to try to break your AI app on purpose so you can fix problems before real attackers or users find them.

Think of it like…

A fire drill and a fire inspector combined: inspectors check the building against a list, but drills with people who try unexpected exits reveal what the checklist missed, and every discovered problem becomes a new item on the checklist.

Where you’ve seen it

A company red-teams its support agent (RAG plus order-lookup and refund tools). Twelve testers work for five days with a threat model and a coverage matrix of 8 attack categories (direct injection, indirect injection, jailbreak, data extraction, tool abuse, authorization bypass, denial of wallet, harmful content) across 5 surfaces (chat, RAG documents, email intake, tools, admin console). They find 47 issues: 6 critical (for example a poisoned PDF that causes a refund call, caught by the approval gate only because it exceeded $50), 14 high, 19 medium and 8 low. In parallel an automated generator runs 20,000 attack prompts: attack success rate 1.8% (360 successes) that cluster into 31 root causes. Findings go to a tracker with SLAs (critical: 3 days, high: 14 days); each fix adds test cases (the 47 findings become 220 regression tests in CI) and the next month's re-test shows all critical issues closed and ASR down to 0.6%. Coverage reporting shows 36 of 40 matrix cells exercised, with 4 gaps scheduled for the next round.

Words you’ll hear

Threat model
The assets, attackers, entry points and impacts that define what to test.
Coverage matrix
Attack categories crossed with system surfaces, showing what has been tested.
Attack success rate (ASR)
The share of attack attempts that achieve the attacker's goal.
Regression suite
Tests derived from past findings that run on every change.

Visual diagram

Loading interactive diagram

Theory & deep dive

Planning and running a program

Start with a threat model: what can the system access and do, who might attack it (curious users, malicious customers, external attackers, insiders), what are the high-impact outcomes (data exposure, financial loss, harmful content, reputational damage, safety incidents) and what is out of scope. Write rules of engagement (testing environment or production with safeguards, data handling, communication, stop conditions) and a coverage matrix of attack categories and surfaces so you can see what has and hasn't been tested. Typical categories: direct and indirect prompt injection, jailbreaks and policy bypass, system prompt and data extraction, tool and agent abuse (excessive agency, confused deputy), authorization and tenant isolation, supply chain (MCP servers, packages), denial of service and wallet, and harmful or biased output including multi-turn and multilingual cases.

Mix human testers (security engineers, domain experts, trust-and-safety specialists, outside firms) who find novel, multi-step attacks and business-logic flaws, with automated tools that generate and mutate thousands of attacks, run them against the system and score outcomes (PyRIT, garak, promptfoo, in-house fuzzers, LLM-based attackers). Automation gives breadth and regression coverage; humans give depth and creativity. Test the whole system, not only the model: retrieval, tools, permissions, UI rendering, logging and operations. Use realistic data and credentials in staging, and consider a bug bounty or external review for public products.

A coverage matrix

8 attack categories × 5 surfaces (chat, RAG documents, email intake, tools, admin console) = 40 cells. After round one, 36 cells have at least one test; the 4 untested cells (for example, denial-of-wallet via email intake) are scheduled for round two.

Key takeaway: Define scope and a coverage matrix, combine human creativity with automated scale and test the whole system.

Findings, severity, remediation and metrics

Record each finding with a reproducible description (input, context, expected vs actual behaviour), the impact, affected component, evidence (trace ids, logs), and a severity based on impact and exploitability (for example critical: unauthorised action or data exposure with realistic prerequisites; high: significant policy bypass; medium: limited harm; low: cosmetic). Set SLAs (critical 3 days, high 14), assign owners and verify fixes by re-running the original attack and variants. Prefer structural fixes (authorisation, approval gates, sandboxing, egress controls, least privilege) over prompt patches, which often fix one phrasing and leave the vulnerability. Convert every finding into one or more regression tests (47 findings produced 220 tests) and add variants generated by mutation.

Measure the program: ASR by category (1.8% overall in the automated run, 0.6% after fixes), number and severity of findings, time to remediate, coverage of the matrix, repeat findings (the same root cause appearing again signals weak fixes) and the proportion of issues found by automation versus humans. Report trends to leadership with risk framing, not just counts. Keep the program continuous: run automated suites in CI on every prompt, model, tool or data change, schedule manual rounds quarterly or before major releases, and feed in real incidents and new public techniques. Maintain ethics and safety: protect testers from harmful content exposure, handle sensitive findings with restricted disclosure and share lessons across teams.

From finding to regression test

Finding: a poisoned PDF instructs the agent to refund $75. Fix: refunds above $50 require approval and the order must match the user. Tests added: the original PDF, 12 paraphrased variants, 3 amounts around the $50 threshold and a cross-user order id. All 17 tests run in CI with a gate on action-level ASR.

Key takeaway: Rate severity, fix structurally with SLAs, verify, convert findings into regression tests and track ASR, coverage and repeat findings.

How it works, step by step

Step 1 of 4
Security lead

1. Scope and plan

Write the threat model, rules of engagement and a coverage matrix of attack categories by surface.

8 categories × 5 surfaces
Key numbers at this step
Define
stop conditions

When to use it & trade-offs

What it is

Red teaming for AI is a structured program of adversarial testing: people (and automated tools) deliberately try to make the system fail in harmful ways, such as prompt injection, jailbreaks, data extraction, tool abuse, privilege escalation, unsafe or biased outputs and denial of wallet, then record findings, rate severity, drive remediation and convert each finding into a regression test. A good program has a defined scope and threat model, a mix of manual creativity and automation at scale (frameworks such as PyRIT, garak or promptfoo), measurable coverage across attack categories and surfaces, clear severity and SLA rules and a feedback loop so fixes are verified and stay fixed.

Why it matters: Static checklists and happy-path evals miss how real attackers behave: they chain steps, exploit the tools and data around the model and adapt. AI systems also change constantly (new models, prompts, tools, data), so a one-off pre-launch pentest decays quickly. Continuous red teaming finds problems before users or attackers do, produces concrete evidence for risk decisions and builds the regression suite that keeps safeguards from silently degrading.

When to reach for it

  • Before launching AI features and after major changes
  • Continuous regression testing of safeguards
  • Evidence for risk acceptance and compliance

When to avoid or be careful

  • One-off testing with no remediation tracking
  • Fixing findings only with prompt patches
  • Testing only the model and ignoring tools, data and UI

Testing approaches

Manual red teaming
Best for: Novel, multi-step and business-logic attacks

Strengths: Creative; finds what automation misses.

Watch out: Expensive and not repeatable at scale.

Automated attack suites
Best for: Breadth, regression and CI gating

Strengths: Fast, repeatable, measurable.

Watch out: Limited to known patterns and generators.

Bug bounty and external review
Best for: Public-facing products

Strengths: Diverse attackers; real-world perspective.

Watch out: Needs triage capacity and clear scope.

Interview signals & numbers to know

When this topic comes up

  • “Has anyone tried to break it?”
  • Attack success rate
  • PyRIT, garak and promptfoo
  • Coverage matrix
  • Regression tests from findings

Benchmarks & rules of thumb

47 findings -
6 critical · 14 high · 19 medium · 8 low
1.8% → 0.6% -
automated attack success rate before and after fixes
36 of 40 -
matrix cells covered after round one

Common mistakes & follow-ups

Common interview mistakes

  • Reporting findings without owners or deadlines.
  • Closing a finding after fixing only the exact reproduced prompt.
  • Never repeating the exercise after the system changes.

Likely interviewer follow-ups

  • How would you run a red-team exercise for an AI agent?
  • How do you turn findings into lasting protection?
  • What metrics show the program is working?
Interview tip: Show the loop: findings become regression tests that gate CI. It proves red teaming improves the system over time instead of producing a report.
Loading hands-on exercise

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Red Teaming with generative AI interview Q&A and hands-on practice.

Open Generative AI Q&A →Tech Learn Q&A
Previous topic
Audit Logging
Next topic
Docker