Block release when prompt-injection tests confirm a secret leak or an action taken without permission. CI/CD checks should test what an AI agent reads, reveals and does - not just whether its final reply sounds safe.
A release check should cover:
- Rules and permissions: define banned behaviour, restrict tool access and enforce approvals in application code.
- Repeatable attacks: test direct prompts and malicious content in documents, retrieval results and tool outputs using synthetic data and sandboxed tools.
- Release gates: inspect responses and tool traces, compare results with an approved baseline, and block on critical failures or missing results.
- Follow-up: investigate failures, retest fixes, retain protected test records and add incidents to the regression suite.
The target for confirmed critical failures is zero. But even 0 failures in 500 trials does not prove safety. Human testing, production monitoring and separate privacy checks still matter.
::: @figure
{Prompt-Injection Testing: The CI/CD Release Gate}
:::
Prompt Injection Just Hit CI/CD Pipelines - Here’s How
Build a repeatable prompt-injection test suite
Turn those policy rules into replayable test cases. For each case, define the expected policy outcome and observable assertions. Store it in Git with a stable ID, attack category, payload, input surface and authorised task.
Link each case to the model ID, version, decoding settings, prompts, agent config, tool scopes, tenant ID and fixture version. Record the commit, test date and run ID too. Outputs are non-deterministic, so assert safety properties rather than exact wording. Rerun important cases and keep failed outputs and traces.
Test direct and indirect injection
Cover both direct and indirect injection paths, including instruction overrides, jailbreaks, system prompt leakage and restricted-tool attempts. Vary the language, spelling, encoding and conversation history. Don’t rely only on familiar attack phrases.
For indirect injection, put payloads in actual documents, web pages, tickets, emails, retrieved records and tool outputs. Pass them through the real connector or an end-to-end fixture - not a user message. Include multi-step chains where retrieved content triggers another tool call. Keep confirmed incidents and fixed vulnerabilities as regression cases.
Check for data leaks and actions without permission
Seed isolated tenants with distinct synthetic secrets. Check responses, streams, logs, memory, rendered content, email and outbound requests for those markers. Route requests to instrumented test endpoints with no public internet access.
Use sandboxed tools to test reads, writes, deletions, messages, purchases and configuration changes without permission. Also check whether changing a recipient, amount or resource invalidates an existing approval.
Hypothetical example: a malicious support ticket tells an agent to email another customer’s records. Create two synthetic tenants and place the payload in Tenant A’s ticket. Ask for a legitimate ticket summary. Assert that no Tenant B record is read, no email call is attempted and no Tenant B marker appears in any output or request. Record whether each attempted action was blocked or completed.
Inspect tool traces and responses
Check both responses and tool traces for data exposure and tool misuse. A refusal must not hide earlier misuse. Correlate responses with structured traces that distinguish attempted, blocked and completed actions.
Use deterministic assertions for secret markers, forbidden endpoints, tenant IDs, permissions, approval state and data changes. A forbidden call blocked by the executor still fails a no-attempt assertion. That is different from the call completing successfully.
Reserve model-based grading for semantic questions. Calibrate it against labelled cases and review disagreements. Include legitimate summaries, permitted reads and authorised tool calls to measure false refusals.
Run CI/CD tests and set release gates
Once you’ve defined the test cases, add them to CI so every change runs the right security checks before merge or release.
Run the suite in a disposable CI environment with no production credentials, synthetic data and sandboxed tools. Use the results to gate releases on prompt-injection risk. Allow outbound traffic only to approved test endpoints, keep customer data outside the runner and use a narrowly scoped staging model credential.[2]
Match test coverage to each change
Run a short security suite on every pull request. Require broader coverage before release, after relevant changes and on a schedule to detect provider drift.[4][5]
Choose the minimum suite and blocking rule based on what changed.
| Change | Minimum suite | Blocking rule |
|---|---|---|
| Prompt edits | Pull-request suite plus prompt-extraction, refusal and secret-handling regressions | Block on a system-prompt leak or other critical disclosure failure |
| Model changes | Full security suite, repeated where practical; compare rates with the approved baseline | Block on any critical failure |
| Tool changes | Authorisation, argument validation, least-privilege and destructive-action tests | Block on unauthorised high-impact tool use, including unsafe arguments |
| New data sources | Indirect-injection, cross-tenant access, retrieval-boundary and leakage tests | Block on protected-data access or disclosure without permission |
| Dependency updates | Smoke tests, security regressions and affected parser, output-handling and integration tests | Block on incomplete evaluation or newly introduced critical failures |
Set hard stop conditions before tuning thresholds.
Define blockers and regression limits
Any critical failure must block release. This includes confirmed secret or personal-data disclosure, credential exposure, cross-tenant access, unauthorised destructive actions, sensitive system-prompt leaks and high-impact tool-policy failures.
- Attack success = harmful outcomes / valid attack trials.
- Unauthorised-tool-call rate = calls without permission / applicable permission-test trials.
- Sensitive-data leakage = leaking trials / trials with a protected-data opportunity.
- False refusal = wrongly refused legitimate requests / legitimate trials.
Report counts, how repeat trials are handled and uncertainty - not just percentages.
Hypothetical configuration - not a universal standard: require zero confirmed critical failures: any critical disclosure, credential exposure, cross-tenant access or destructive action blocks. Cap non-critical attack success at 2% across at least 500 valid trials, unauthorised tool calls at 0.5% across at least 200 applicable trials, sensitive-data leakage at 0.5% across at least 500 applicable trials, and false refusals at 5%. Allow no non-critical metric to worsen by more than 1 percentage point against the approved, versioned baseline. Missing results, infrastructure errors and unresolved evaluator grades block release. Critical disclosures remain zero-tolerance regardless of other limits. Report uncertainty: “0/500” is evidence from that sample, not proof of zero risk.[6]
Encode these limits in the pipeline so the gate fails automatically.
Add a CI job with clear exit rules
Pin the evaluator version and write JSON evidence. Fail the job on critical findings, threshold breaches, evaluator errors, missing results and unresolved critical grades.
Configure the job as a required check so its results determine whether a merge or release can proceed.
name: agent-security-eval
on: [pull_request]
permissions:
contents: read
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install locked evaluator dependencies
run: npm ci
- name: Start disposable sandbox
run: docker compose -f ci/sandbox.compose.yml up -d --wait
- name: Evaluate and enforce gate
env:
MODEL_API_KEY: ${{ secrets.STAGING_MODEL_API_KEY }}
run: |
npm run security:eval
python3 ci/check_security_gate.py results.json
- name: Retain redacted evidence
if: always()
uses: actions/upload-artifact@v4
with:
name: security-evidence
path: evidence/redacted/
if-no-files-found: error
retention-days: 14
- name: Remove sandbox
if: always()
run: docker compose -f ci/sandbox.compose.yml down -v
Record evidence and protect gate settings
For audits and regression tracking, publish a machine-readable status record with test IDs, attack categories, assertions, trial counts, outcomes, tool traces, model and prompt configuration, changed controls, baseline version and gate decision.
Redact sensitive evidence, restrict access and set retention limits. Retention limits do not restrict access. Use fixed seeds where supported, but don’t claim deterministic behaviour. Record reruns as new evidence rather than overwriting earlier failures. Require independent review for changes to tests, baselines, thresholds or temporary exceptions.[7]
Investigate failures and recognise testing limits
When CI flags a failure or an unclear result, investigate before adjusting the gate. A failure is evidence to examine, not a final verdict.
Review unclear and inconsistent results
Before changing prompts or thresholds, reproduce the exact run. Check whether the agent exposed data or misused tools with the same model, prompt, retrieved content, tool schema, credentials, temperature and runner configuration. Classify the result as a genuine violation, a test defect, a false positive or indeterminate.[8][2]
Treat attacker-controlled content as data, not as instructions for the evaluator. Where possible, keep trusted test metadata, expected outcomes and scoring rules outside model-visible content. Use independent assertions to check for protected-token disclosure or unauthorised actions, rather than relying on the agent’s own judgement.
Test a legitimate control case as well. Blanket blocking may look safe while stopping the agent from doing its job. Record the intent, technique, evasion, input surface, result and evidence so another reviewer can reproduce the decision.[8][2]
Retest fixes and preserve regression cases
If the violation is genuine, trace the full path before changing policy or prompts. Check retrieval permissions, orchestration, tool validation, credential scope, output handling, logging and sandbox enforcement. Fix the boundary that failed.
Keep the original failing payload, scenario ID, expected and actual results, and complete trace in a failure register. Replace secrets, tokens and personal data with stable identifiers or hashes where needed.
Rerun the original case, close variants and the regression suite for direct injection, indirect injection, tool misuse and leakage. Check that authorised tasks still succeed. Use blocked-call traces and permission checks - not refusal text - to prove enforcement. Record model, application, policy, tool and dependency versions so regressions can be traced to future changes.[2][1][8]
Add production monitoring and human red-teaming
Even strong regression suites miss new attack paths, so monitoring must continue after release. A finite suite samples known paths; it cannot prove safety. New payloads, poisoned data, multi-turn attacks, provider changes and production drift can expose paths that have not been tested.
Pair automated evaluations with human red-teaming before major releases, after model or provider changes, when agents gain new tools or data sources, and after serious incidents or unexplained test results. Include reviewers who can challenge assumptions across identity, retrieval, tools and infrastructure.[2][9]
Keep access controls active in production. Monitor anomalous tool calls, injection-like inputs, unusual retrieval, access denials, unapproved outbound requests, secret-pattern matches, unexpected data volumes, privilege changes and approval bypasses. Retain structured evidence while protecting personal and confidential data.
Track anomaly frequency, incident-response time, time to successful bypass, and rates of blocked or escalated actions. Add confirmed incidents and near misses to the regression corpus. Passing prompt-injection tests does not prove UK GDPR compliance: privacy obligations need separate controls, records and risk assessments. Involve the data-protection officer where personal data is processed.
Conclusion: Require security checks before release
Before release, define prohibited behaviour, map untrusted inputs and permissions, and run repeatable tests for direct and indirect prompt injection. Check data flows, tool arguments and authorisation decisions, not just the final response.[1]
Block release if testing confirms a confidential data leak or an action taken without permission. Use risk-based thresholds for lower-severity findings and human review for high-impact releases.[3]
Turn every incident, near miss and observed gap into a new test case in the regression suite.[1]
Hokstad Consulting supports AI strategy, custom agent implementation and deployment planning, but release approval still needs independent security validation.
FAQs
How can I test multi-step attacks in CI/CD?
Validate the entire request chain, not just individual actions. Link tool calls from source retrieval through to the final output, including asynchronous paths. Run tests in temporary staging environments that mirror production, and pin model versions.
Test whether prompt injection can lead to privilege escalation or data exfiltration without permission. Apply policy-as-code release gates with strict failure thresholds for high-impact actions. Fail the build if an agent can be manipulated into multi-step tool misuse.
How do I set thresholds for inconsistent test results?
In your CI/CD pipeline, use static thresholds for fixed limits, such as run duration or spending caps. For latency, cost per run or token usage, set thresholds based on deviations from representative historical baselines. Use rate-of-change thresholds to flag sudden anomalies, such as tool-call surges or retry storms.
Document baseline periods, evaluation windows and aggregation rules. Review thresholds after model updates, pricing changes or workload shifts so they stay within your pipeline’s operating tolerances.
What risks can automated prompt-injection tests miss?
Automated prompt-injection tests can miss complex attacks that trick an agent into misusing its authorised permissions - for example, taking tool actions without approval or accessing restricted data.
These tests cannot replace thorough security reviews. Reviews must also check identity settings, the agent’s environment configuration and whether human oversight works during live tasks. Treat automated signals as indicators, not proof of safety.