Skip to Content
AI security controls and defensive layers

AI security controls

Security controls for AI systems, technical, administrative and operational, across the usage, application and platform layers.

Aug 29, 2025
Updated Nov 22, 2026
6 min read

Introduction

Controls for the risks specific to AI systems, across the human-facing, application and platform layers. This is written as a playbook for engineering teams, and on an assessment it doubles as the list of things I check for.

Why this matters

AI risk amplification

With large models, a small mistake in a prompt, a retrieval or the training data can cause a data leak, unsafe output or a poisoned model. AI failures are often subtle and hard to predict, and they hit every user at once.

The patterns below are engineering controls you can put in place now and tighten as the risk grows.

Core principles

  1. Minimize trust. Treat external text and connectors as hostile by default.
  2. Pin and verify. Critical configuration and artifacts should be auditable and verifiable.
  3. Fail safe. For high-risk flows, block or send to human review.
  4. Log and measure everything. Detection and tuning depend on it.
  5. Test adversarially, all the time, with red team prompts and automated regression tests.

Workflow map

  1. Input intake (human or machine) -> 2. Sanitization and classification -> 3. Retrieval and enrichment -> 4. Prompt composition (system + context + user) -> 5. Model call -> 6. Post-processing and safety checks -> 7. Action, response or human review.

Defense in depth

Put a guard at every boundary in this workflow. Each hand-off between components is a place where input needs validating, sanitizing and monitoring.

Controls by layer

Human-facing layer (interaction and UI)

Goal: stop users or attackers from changing what the system is told to do, and from collecting sensitive responses.

  • Keep the part of the prompt that defines behavior (intent, policy, blocking rules) in a versioned config file that can't be edited at runtime. Deploy changes only through CI with approval.
  • Push user uploads and text through a classifier that assigns a sensitivity bucket (public, internal, secret). The bucket decides whether the content can be retrieved later or used for training.
  • Run lightweight checks in the client (length limits, forbidden patterns) to stop obvious mass-extraction attempts before they reach the server.
  • For high-risk categories (legal advice, payroll, account termination), require human sign-off before any action or release.

Application layer (ingest, retrieval, orchestration)

Goal: everything that feeds the model is traceable and tamper-evident.

  • Index data only from approved sources. At retrieval time, attach source-id, timestamp and sha256 to each snippet and pass that metadata in the prompt.
  • Canonicalize retrieved text: normalize whitespace and Unicode, strip hidden control characters, remove instruction-like tokens.
  • Set a strict byte or character budget for context. Short excerpts with clear provenance beat long verbatim documents.
  • Split features into zones (read-only RAG, write-enabled automation). Enforce RBAC per feature and require MFA or approval for the dangerous zones.

Example: if a retrieval comes from an unverified bucket, mark it quarantine and keep it out of prompts until it's verified.

Platform and training layer (data, pipelines, artifacts)

Goal: less surface for poisoning and theft, and verifiable artifact integrity.

  • Keep a dataset ledger: for every dataset, an immutable record of source URI, ingest time, pre-processing hash and operator ID, in an append-only store or signed log.
  • Seed datasets with non-sensitive canary records. If they show up outside, someone extracted data or the model memorized it.
  • Sign model weights and manifests. Deploy only signed artifacts, and keep rollback checkpoints with cryptographic provenance.
  • Run sensitive training jobs in ephemeral environments with restricted network access, strict write controls and monitored I/O.

Detection and telemetry

The minimum useful trace per model call:

  • user_id, request_id, timestamp
  • system_prompt_id + commit/hash
  • retrieved_snippets: [{id, url, hash, score}]
  • model_name, model_version, temperature, max_tokens
  • final_output + post-filter labels
  • downstream actions (API calls, DB writes)

That trace is what you triage, replay and investigate with.

Signals to alert on:

  • spikes in flagged outputs (policy violations)
  • repeated long retrievals, or identical context requested by many users (extraction probes)
  • unexpected changes to system_prompt_id, or failed signature checks
  • anomalous grounding scores (many unsupported claims)

Safety patterns

  • Before the system uses a new external connector, require admin approval plus a signed challenge-response that proves control of the connector.
  • Compute a grounding score: output claims backed by retrieved snippets divided by total claims. Below a threshold, force human review.
  • Run risky prompts in a restricted sandbox with stricter filters and a smaller token budget, and only pass successful outputs on to other systems.
  • Plant obvious extraction triggers (honeypot prompts) and alert when automated scanners hit them.

Incident playbook

  1. Snapshot. Preserve logging for the affected sessions and copy model call traces and retrieval metadata to immutable storage.
  2. Quarantine. Revoke the API keys involved, and suspend the affected model deployment or route traffic to a known-safe model.
  3. Scope. Run provenance queries to find which datasets or connectors were involved, and check the canary records and dataset ledger.
  4. Remediate. Rotate keys, remove or reindex poisoned data, roll back to the last signed checkpoint.
  5. Post-mortem. Write up the timeline, root cause and fix, and add automated tests so it doesn't recur.

Keep a forensics runbook that scripts the artifact collection, so nobody improvises during an incident.

Templates and examples

Minimal context envelope (JSON-style)

{
  "system_config_id": "sys-20250829-v3",
  "system_seal": "sha256:abc...",
  "context": [
    {
      "id": "doc-17",
      "source": "s3://approved-bucket/reports/2025-05",
      "excerpt": "First 1024 chars...",
      "hash": "sha256:..."
    }
  ],
  "user": {
    "id": "u-42",
    "input": "Summarize vendor contract..."
  }
}

Rules:

  • Reject any context entry whose hash is missing or doesn't match.
  • Cap the excerpt size and send annotated snippets (highlights) rather than full documents.

Safe prompt scaffold (runtime)

=== SYSTEM (immutable) ===
purpose: "assistant confined to summarisation and citation-only"
policy: "do not provide personal data, do not perform actions"
=== RETRIEVALS ===
[doc-17 | s3://... | sha256:...]
=== USER REQUEST ===
"Summarize and list action items."
=== RULES (runtime enforced) ===
- if any citation unsupported -> append "UNSUPPORTED" marker and flag for review

Checklist for engineers

  • system prompts are versioned and immutable in CI
  • every retrieval includes source-id and sha256
  • pre and post filters run on every model call
  • RBAC and short-lived credentials for connectors and keys
  • model artifacts are signed and deployment verifies the signatures
  • a baseline adversarial prompt corpus with CI tests
  • monitoring for extraction, grounding and prompt changes

Prioritization

TimeframeWhat to do
DaysMake prompts immutable, turn on pre and post filters, add retrieval metadata
WeeksSigned artifacts, scoped short-lived keys, basic anomaly alerts
MonthsDataset ledger, canary records, differential privacy or synthetic data pipelines for sensitive training

On this page