Zulia Shavaeva← Back to Zulia

Learn / Detection, logging and response for AI systems

Detection, logging and response for AI systems

Knowing what an attack on an LLM or agent looks like in logs, which signals to collect, and how to respond when a model or agent misbehaves.

Before the exercises: Understand logs, alerts and incident handling. For metric exercises, know how to count events and separate true from false detections. Start with Step 0 if needed.

Researched on 2026-09-26 with AI assistance. Links and summaries can change; verify details with the original source. Not yet reviewed by a person.

What it is

Detection and response for AI systems means collecting telemetry from model calls, agent tool calls and the hosts that run them, then deciding what normal looks like and what to do when it is not. The UK NCSC puts this in the operation and maintenance stage of the AI lifecycle: measure model and system outputs so you can see sudden and gradual behaviour changes affecting security, and log inputs such as inference requests, queries and prompts so you can audit, investigate and remediate after misuse or compromise.4

It is partly a new data problem. OpenTelemetry defines GenAI span conventions with fields such as gen_ai.operation.name, gen_ai.provider.name, gen_ai.request.model, gen_ai.agent.id and error.type, with prompts and system instructions treated as opt-in rather than default content; the conventions are still marked Status: Development and have moved to a dedicated repository.23

It is also an old detection problem with a new parent process. Elastic Security Labs' write-up of the July 2026 Hugging Face intrusion, the single published account of it and not independently confirmed, describes an agent-driven chain starting with untrusted dataset content abusing a config-driven loader in a production Kubernetes worker pod (local file disclosure via an HDF5 external raw-storage page, then Jinja2 template injection for code execution), then credential harvest and multi-cluster lateral movement, behaviours that existing endpoint and SIEM rules already watch.6

The response side needs its own runbook. OWASP's GenAI Security Project commissioned the GenAI Incident Response Guide 1.0 (published 28 July 2025) for security practitioners generally, explicitly not assuming deep GenAI knowledge, and NIST published AI 800-4 on the challenges of monitoring deployed AI systems in March 2026.189

In the job-posting sample

Counts describe 48 postings collected on 24 September 2026. Small role samples do not establish market-wide requirements or explain employer decisions.

Across 48 postings, 4 ask for this skill (8%). On that denominator the only safe reading is that it is a narrow ask in this sample; the postings that carry it are ones where someone specifies or operates the telemetry pipeline.P

29% of the 7 AI Security Architect postings ask for it, against 12% of 16 AI/Agent Security Engineer postings. The tasks named in those postings differ: architects decide which prompt, tool-call and host signals get collected and retained, engineers wire the traces and guardrail events into a pipeline the SOC can query.P24

Research, red team, GRC and consulting clusters ask at 0% in this sample. The content still transfers to engineer and architect applications, because the Hugging Face chain, as published, was detected largely by conventional rules.P6

Key terms and concepts

Start with the meaning, then connect it to an example. Use these notes while learning or revising; explaining a term is one part of applying it.

False positives and false negatives

A false positive is an alert on a benign case. A false negative is a missed case that should have triggered an alert. Both depend on a defined target and trustworthy test labels.14

Example: A detector flags a harmless security-training example but misses an actual attempt to redirect an agent. The first is a false positive; the second is a false negative.

Security connection: Test benign use as well as attacks. Define success by the security outcome you care about, and assess the cost of needless blocking alongside missed incidents.

Precision and recall

Precision is the fraction of alerts that are correct: true positives divided by all positive predictions. Recall is the fraction of actual positive cases detected: true positives divided by all actual positives.14

Example: In a fictional test, there are 20 attacks. A detector raises 15 alerts; 12 identify attacks. Precision is 12/15 = 80%. Recall is 12/20 = 60%.

Security connection: Report the test set, threshold and counts with each percentage. Results on a small fixed test set are not a promise of production performance.

GenAI telemetry schema

OpenTelemetry's GenAI conventions model a model call as a span with required attributes gen_ai.operation.name and gen_ai.provider.name, plus conditionally required fields like gen_ai.request.model, gen_ai.agent.id, gen_ai.agent.name, gen_ai.agent.version, server.address and error.type. Full system instructions are Opt-In, not Recommended, so prompt content is a deliberate collection decision. The conventions are Status: Development and moved out of the main semantic-conventions repository, so pin a version before building detections on field names.23

Logging prompts without breaking privacy rules

NCSC tells providers to monitor and log inputs such as inference requests, queries and prompts in line with privacy and data protection requirements, so that compliance, audit, investigation and remediation are possible after compromise or misuse. That includes explicit detection of out-of-distribution or adversarial inputs, including inputs aimed at data preparation steps such as image cropping and resizing. In practice you negotiate retention, redaction and access controls before you get prompt text into the SIEM.4

Behaviour baselines and drift

NCSC's operation and maintenance guidance asks you to measure model and system outputs and performance so you can observe both sudden and gradual behaviour change, and to distinguish intrusions and compromises from natural data drift. The same section notes that changes to data, models or prompts can change system behaviour, so major updates should be treated like new versions. A detection baseline that is not versioned against the model and prompt will produce alert storms after every release.4

Expected input profiles

NCSC's machine learning principles set a goal of knowing what expected inputs look like as part of monitoring and logging user activity at the deployment stage. That profile is what lets you flag unusual query volume, repeated probing or inputs shaped unlike your traffic. It is the AI equivalent of knowing your normal API callers before you try to spot abuse.5

Platform detections and their scope limits

Microsoft Defender for Cloud's threat protection for AI services is generally available and produces alerts for threats including data leakage, data poisoning, jailbreak and credential theft, using Azure AI Content Safety Prompt Shields and Microsoft threat intelligence, with prompt evidence in alerts and Defender XDR integration. The documented limits matter for coverage planning: supported services are Azure OpenAI and Azure AI Model Inference models, only text tokens are scanned (not image or audio), Azure Government and connected AWS accounts are not supported, and enabling detection at subscription level needs Owner or equivalent data actions. Billing is on the Defender for Cloud pricing page with a 30-day free trial capped at 75 billion tokens scanned.7

Outcome detections around agent hosts

Elastic's mapping of the Hugging Face intrusion argues for outcome detections (credential file paths, unusual egress destinations, persistence created under GenAI parent processes) rather than trusting an agent or worker process tree wholesale, because the agent drove ordinary intrusion techniques. Production rules that watch workers spawning shells, interpreters and downloaders still applied to the initial access stage. That means your existing EDR and SIEM content is the starting point, retargeted at ML workers and GenAI hosts.6

Alert volume in agentic incidents

In Elastic's account of the Hugging Face intrusion, the defenders reconstructed roughly 17,600 attacker actions over about 9-13 July UTC, with self-migrating command and control on public services and a swarm of short-lived sandboxes. That figure is one organisation's reconstruction of one incident, so use it to argue that agentic campaigns can spike alert volume, not as an industry benchmark. The operational advice travels better: tune noisy mechanics by process lineage, and keep credential and egress outcomes as high-priority signals. Investigation load, not detection coverage alone, is the constraint.6

Guardrail output is evidence, not proof

Published evaluations show injection defences are fragile: one study evaluated eight defences against indirect prompt injection on LLM agents and bypassed all of them with adaptive attacks, and another formally characterises why known-answer detection schemes that looked near-perfect can be defeated. Both are preprints, so read them as evidence that guardrail verdicts are one telemetry stream to log and correlate rather than a control you can report as coverage. Forensics can also be blocked by safety filters: in Elastic's account, Hugging Face rebuilt its timeline with its own LLM analysis agents after hosted frontier APIs refused forensic payloads.11126

Use fictional data and authorised sandboxes. Remove employer details and secrets from any portfolio write-up. Time estimates exclude setup. Check model and cloud costs before running tests, set spending limits, and delete lab resources afterwards.

Three exercises

Work through these in order. Open-source code can still incur model, cloud or hardware costs. Record your setup, results and limitations.

1Write the GenAI logging requirement an app team can implementabout 3 h

A one-page field spec you can defend in a design review, showing which GenAI span attributes you require, which are opt-in, and which three detections each field supports.234

  1. Read the OpenTelemetry GenAI agent span page and list required, conditionally required, recommended and opt-in attributes.
  2. Mark the version or commit you read, since the conventions are Status: Development and recently moved repositories.
  3. Map each field to at least one detection idea (for example unexpected gen_ai.request.model, error.type spikes, unknown gen_ai.agent.id).
  4. Add a prompt-content section stating retention, redaction and access controls, using the NCSC wording on logging inputs in line with privacy requirements.
  5. Write one sample log record in JSON and one query you would run against it.

Tools: text editor, OpenTelemetry GenAI semantic conventions docs

Check your work
  • The field spec records the OpenTelemetry convention version or commit you read, and classifies every attribute you require as required, conditionally required, recommended or opt-in.
  • The sample JSON record contains exactly the fields you specified and the sample query references only those names; the prompt-content section states a retention period, a redaction rule and who may read the content.
2Turn the Hugging Face agentic intrusion into detection hypothesesabout 4 h

A stage-by-stage detection table for an ML worker and GenAI host estate, with the data source each detection needs and a note on which are outcome detections.6

  1. From the Elastic write-up, write the stages in order: untrusted dataset config, local file disclosure, template injection code execution, credential harvest, lateral movement and C2.
  2. For each stage name the telemetry you would need (process events, file reads of credential paths, network egress, Kubernetes audit logs).
  3. Write five detection hypotheses and label each as behaviour-based or outcome-based.
  4. For two of them, write the query in whatever SIEM language you already use and state the expected false positive source.
  5. Add a triage note on lineage-based tuning and on the roughly 17,600 reconstructed actions that drove alert volume.

Tools: text editor, any SIEM or EDR query language you already use

Check your work
  • Each stage in the table names at least one telemetry source and says whether the stage is evidenced in the published write-up or inferred by you.
  • Two hypotheses are written as runnable queries in your own SIEM language with a named expected false-positive source each, and every hypothesis is labelled behaviour-based or outcome-based.
3Detect injected tool calls in agent traces using AgentDojoabout 8 h

Evidence that you can generate real agent traces under attack and write trace-level rules that flag tool calls the user never asked for, with measured false positives.1011

  1. Install AgentDojo, the open source environment for evaluating prompt injection attacks and defences on tool-using agents, and run a benign task suite to capture baseline traces.
  2. Run the injection task suites and export traces for both runs.
  3. Write a rule that flags any tool call not implied by the user task, and a second rule that flags tool sequences appearing only in attacked runs.
  4. Measure how many benign runs your rules would have alerted on, and record the rate.
  5. Repeat with one defence enabled and note that published adaptive attacks have bypassed all eight defences in one evaluation, so report residual risk rather than coverage.

Tools: AgentDojo, Python, a local model runtime or a free API tier, text editor

Check your work
  • You have exported trace files from a benign run and an attacked run of the same suite, with model, suite name and AgentDojo version recorded.
  • Both rules are run against the benign traces and the benign alert count is reported as a rate with its denominator, independently of whether any attack in the suite succeeded.

Practice questions

Written from the concepts above, not collected from a named employer. Open one, answer it out loud, then tick the points you covered; the score stays in this browser.

An app team is shipping an LLM feature next month. What telemetry do you require before go-live, and what do you deliberately not collect?GenAI telemetry schema

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

How would you tell a compromise apart from the model simply drifting or being updated?Behaviour baselines and drift

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

Your organisation enables a managed AI threat protection service. What do you still have to build yourself?Platform detections and their scope limits

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

Walk me through detecting the Hugging Face style agentic intrusion in an ML platform you own.Outcome detections around agent hosts

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

Why should a SOC not treat a prompt injection classifier as a control it can report as coverage?Guardrail output is evidence, not proof

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

An agent incident generates thousands of events in days. How do you keep triage viable?Alert volume in agentic incidents

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

What does an incident response plan for a GenAI application contain that a standard plan does not?GenAI Incident Response Guide 1.0

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

How would you prove, in a lab, that you can detect an injected tool call?AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents

Say your answer out loud or write it down, then tick what you covered:

0 of 4 covered

Sources

Every numbered claim above links here. P = the platform's own coding of 48 job postings.

  1. GenAI Incident Response Guide 1.0 OWASP GenAI Security Project
  2. Semantic Conventions for GenAI agent and framework spans OpenTelemetry
  3. gen-ai-spans.md (moved notice, semantic-conventions repository) OpenTelemetry
  4. Guidelines for secure AI system development: Secure operation and maintenance UK NCSC
  5. Machine learning principles 3.2 Monitor and log user activity UK NCSC
  6. Hugging Face breach: GenAI detection with Elastic Defend Elastic Security Labs
  7. AI threat protection in Microsoft Defender for Cloud Microsoft
  8. NIST AI 800-4: Challenges to the Monitoring of Deployed AI Systems (PDF) NIST
  9. Challenges to the monitoring of deployed AI systems (publication record, published 6 March 2026) NIST
  10. AgentDojo: A Dynamic Environment to Evaluate Prompt Injection Attacks and Defenses for LLM Agents arXiv (ETH Zurich SPY Lab)
  11. Adaptive Attacks Break Defenses Against Indirect Prompt Injection Attacks on LLM Agents arXiv
  12. How Not to Detect Prompt Injections with an LLM arXiv
  13. Guidelines for secure AI system development (collection overview) UK NCSC
  14. Precision and recall scikit-learn

Resources

Free first. Levels: intro means no prior knowledge of this skill; working means you can apply it on a project; advanced means research depth or specialist tooling.

Level Format

Gaps the research could not fill with a good free source: No vendor-neutral open detection content for LLM and agent telemetry: the only concrete rules found were tied to one SIEM and to AWS Bedrock logs, and no free Sigma rule set turned up.; No free blue-team range or CTF where you triage a full AI incident from logs and traces end to end; the free hands-on material found is offensive or guardrail building.; No free primary guidance on retention, redaction and privacy handling of prompt, completion and tool-call logs, which GRC leads ask about first.; No free provider-confirmed course dedicated to AI incident response; every AI IR source found today is a document, not training with stated hours.; Could not re-confirm today, within the search budget, the URLs already on the site (MITRE ATLAS, AI Incident Database, LLM Guard, Purple Llama, Defender for Cloud AI threat protection, Bedrock CloudWatch monitoring), so they are not repeated here and should be kept from the existing index if still live.