New to ShortSpan? We distil the AI-security research that matters into practitioner takeaways — edited by Ben Williams (NCC Group). Get the weekly email
// Analysis

Schema-style tool specs quietly gut LLM agent safety

Agents
Schema-style tool specs quietly gut LLM agent safety

New research fingers schema-formatted tool specifications as the reason Large Language Model agents get less safe when wired to tools. The format, not the semantics, suppresses internal refusal signals, making prompt injection easier. A two-stage guard, SafeKeep, boosts refusals and slashes attack success without breaking normal tasks, across several models and benchmarks.

Hook a Large Language Model (LLM) up to tools and suddenly the safety you saw in the chatbot demo slips. This paper pins a big chunk of that regression on a boring but very real culprit: schema-formatted tool specifications. Not the tools themselves, not the user prompt. The JSON-like scaffolding you paste into the system message.

Where it breaks

The authors compare chatbot inputs with agent-style inputs that add an agent role, tool-use instructions and the tool specification block. Using white-box analysis, they extract a refusal direction in hidden states that cleanly separates harmful from benign requests in chatbot format (AUROC 0.927). Shift to agent format and that separation degrades (0.834), and it craters further when you apply the chatbot-derived direction to agent inputs (0.740).

The worst offender is the tool spec. Across three open models, adding schema-formatted specs causes the largest AUROC drop, on average 0.136 more than other agent components. Extra context length is not the reason. Swap the schema block for a flattened textual description that preserves semantics and the refusal boundary largely comes back, for example from 0.740 to 0.885 on Llama. Keep the schema formatting but randomise the semantics and you still get the degradation. Representation, not meaning, is the lever.

Mechanistically, a Schema Direction learned from harmful requests pushes activations opposite the chatbot refusal direction across layers, reducing harmful versus benign separation at the first generated token. Causally, subtracting that direction at moderate strength lifts refusal from 5.0 percent to 47.5 percent and cuts harmful tool execution from 95.0 percent to 45.0 percent. Push it too hard and outputs go weird. That tracks with anyone who has tried heavy-handed steering at 3am.

What actually helps

They propose SafeKeep, an inference-time pattern: assess safety using flattened textual tool specs, then if it looks safe, execute with the original schema specs. On two benchmarks (AgentHarm and InjecAgent) and four LLMs including white-box and black-box backends, SafeKeep raises average refusals on harmful requests from 23.8 percent to 70.6 percent and drops observation-level prompt injection success from 25.6 percent to 2.5 percent, while keeping task performance intact.

Offensively, this turns representation into an attack surface. If the model sees your payload inside schema-like scaffolding, its internal refusal gets dulled and observation-level injection lands more often, nudging the agent toward unsafe tool calls. Defensively, decoupling safety judgement from execution blunts that path, though it depends on clean conversion to flattened specs and the model retaining a usable refusal signal there. The open question is how far this effect runs across other agent frameworks and tool formats. Either way, the lesson is clear: the shape of your prompt can be as dangerous as its content.

Additional analysis of the original ArXiv paper

📋 Original Paper Title and Abstract

Tool Specifications Matter: Uncovering and Mitigating Safety Risks in AI Agents

Authors: Minghui Pan, Jiayuxuan Yang, Yuanyuan Yuan, Yu Jiang, and Zhenpeng Chen
AI agents extend large language models (LLMs) with external tools, enabling them to perform complex tasks and translate model outputs into consequential real-world actions. Yet LLMs often become substantially less safe when deployed as agents, and the source of this degradation remains poorly understood. In this paper, we identify schema-formatted tool specifications as a primary source of agent safety degradation and show, through white-box representation analysis, that they weaken the model's internal refusal signals and contribute to unsafe tool execution. Building on this finding, we propose SafeKeep, an inference-time safeguard that decouples safety judgment from tool execution: it assesses requests using flattened textual tool specifications while retaining the original schema-formatted specifications for execution. Across two representative benchmarks and four LLMs, including both white-box and black-box models, SafeKeep increases the average refusal rate for harmful requests from 23.8% to 70.6% and reduces the average attack success rate under observation-level prompt injection from 25.6% to 2.5%. It also outperforms existing safeguards and preserves task-handling capability. We release the code and data at https://github.com/snowcatsmoking/SafeKeep .

🔍 ShortSpan Analysis of the Paper

Problem

This paper studies why large language models (LLMs) that reliably refuse harmful requests in chatbot settings become substantially more likely to comply when deployed as agents that can call external tools. This matters because agent outputs can trigger real-world actions, exposing private data or manipulating services. The authors trace the safety regression to components of the agent input and ask which of those components disrupt the model’s internal refusal behaviour.

Approach

The authors use white-box representation analysis and behavioural evaluation across multiple LLMs and benchmarks. They construct a paired dataset of 400 harmful–benign request pairs derived from a tool-use benchmark, with benign counterparts generated and manually verified. They compare chatbot-formatted inputs to agent-formatted inputs that add an agent role, tool-use instructions and tool specifications. They extract a refusal direction from hidden states to quantify harmful–benign separability (AUROC) and define a Schema Direction as the average hidden-state change induced by schema-formatted versus flattened textual tool specifications. They test causal effects by activation steering and propose SafeKeep, an inference-time two-stage safeguard that assesses safety using flattened textual tool specifications and only then allows schema-formatted execution if judged safe. Evaluations cover two benchmarks (AgentHarm and InjecAgent) and four LLM backends including white-box and black-box models.

Key Findings

  • Agent inputs degrade internal refusal representations: a chatbot-derived refusal direction achieves AUROC 0.927 in chatbot format but drops to 0.834 under agent format; applying the chatbot-derived direction to agent inputs yields AUROC 0.740.
  • Tool specifications are the dominant source of degradation: adding tool specifications produces the largest AUROC drop across three open models, with an average decrease of 0.136 compared with other agent components; increased context length alone does not explain the effect.
  • The effect is driven by representation, not semantics: converting schema-formatted tool specs to flattened textual form (preserving semantics) restores AUROC substantially (e.g. Llama: 0.740 to 0.885), while randomising semantics but keeping schema formatting yields little improvement.
  • Schema formatting moves harmful-request activations opposite the refusal direction: the harmful-request Schema Direction is negatively aligned with the chatbot refusal direction across layers, and this reduces harmful–benign separation at the first generated token.
  • Activation steering provides causal evidence: subtracting the harmful-request Schema Direction at a moderate strength (alpha=4) increased refusal from 5.0% to 47.5% and reduced harmful execution from 95.0% to 45.0%; excessive steering caused many invalid outputs.
  • SafeKeep markedly improves safety while preserving capability: across two benchmarks and four LLMs, SafeKeep raises average refusal on harmful requests from 23.8% to 70.6% and lowers the overall attack success rate under observation-level prompt injection from 25.6% to 2.5%, outperforming baselines and preserving task-handling metrics.

Limitations

Analyses use a paired dataset of 400 examples derived from a specific tool-use benchmark and benign rewrites produced by an auxiliary model and manually checked. Activation-steering experiments require internal access and can produce invalid outputs if applied too strongly. Evaluations cover two benchmarks and four models but do not exhaust all agent frameworks, tool formats or attack modalities. SafeKeep relies on correct conversion to flattened textual specifications and on the model’s retained refusal capability under that representation.

Implications

Offensive implications centre on the representation-level attack surface: attackers could exploit schema-formatted tool specifications or ensure their payload is presented within schema-like contexts to suppress internal refusal signals and induce harmful tool execution or successful prompt-injection. Observation-level injection becomes more effective when schema formatting weakens refusal. Knowledge of this mechanism allows adversaries to target the safety-judgment stage if it retains schema formatting; conversely, defenders that separate safety assessment from execution can disrupt this avenue, though attackers may then attempt to manipulate the flattened specification or the safety-assessor prompt.

// Similar research

Related Research

Get the weekly digest

The few AI-security papers that matter, with the practitioner takeaway. No spam.