arXiv(opens in a new tab)cs.CRMar 2025Cited by 116 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2503.18813

Defeating Prompt Injections by Design

Edoardo Debenedetti, Ilia Shumailov, Tianqi Fan, Jamie Hayes, Nicholas Carlini, Daniel Fabian, Christoph Kern, Chongyang Shi, Andreas Terzis, Florian Tramèr

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Edoardo Debenedetti1,3∗^{1,3*}, Ilia Shumailov2^{2}, Tianqi Fan1^{1}, Jamie Hayes2^{2}, Nicholas Carlini2^{2}, Daniel Fabian1^{1}, Christoph Kern1^{1}, Chongyang Shi2^{2}, Andreas Terzis2^{2} and Florian Tramèr3^{3}

1^{1}Google, 2^{2}Google DeepMind, 3^{3}ETH Zurich

Large Language Models (LLMs) are increasingly deployed in agentic systems that interact with an untrusted environment. However, LLM agents are vulnerable to prompt injection attacks when handling untrusted data. In this paper we propose CaMeL, a robust defense that creates a protective system layer around the LLM, securing it even when underlying models are susceptible to attacks. To operate, CaMeL explicitly extracts the control and data flows from the (trusted) query; therefore, the untrusted data retrieved by the LLM can never impact the program flow. To further improve security, CaMeL uses a notion of a capability to prevent the exfiltration of private data over unauthorized data flows by enforcing security policies when tools are called. We demonstrate effectiveness of CaMeL by solving 77% of tasks with provable security (compared to 84% with an undefended system) in AgentDojo.

We release CaMeL at https://github.com/google-research/camel-prompt-injection.

1. Introduction

Large Language Models (LLMs) are increasingly used as the core of modern agentic systems (Wooldridge and Jennings, 1995) interacting with external environments via APIs and user interfaces (Nakano et al., 2021; Thoppilan et al., 2022; Schick et al., 2023; Yao et al., 2022; Qin et al., 2023; Lu et al., 2024; Gao et al., 2023; Shen et al., 2024). This exposes them to prompt injection attacks (Goodside, 2022; Perez and Ribeiro, 2022; Greshake et al., 2023) when data or instructions come from untrusted sources (e.g., from a compromised user, from tool call outputs, or from a web page). In these attacks, adversaries insert malicious instructions into the LLM's context, aiming to exfiltrate data or cause harmful actions (Rehberger, 2024; AI-Security-Team et al., 2025; Anthropic, 2025; OpenAI, 2025).

Current defenses often rely on training or prompting models to adhere to security policies (Wallace et al., 2024; Ghalebikesabi et al., 2024), frequently implemented as vulnerable system prompts (Carlini et al., 2023). This is largely due to the absence of robust methods to formally define and enforce security policies for LLM functionalities on diverse data.

This work introduces a novel defense, CaMeL 1^{1}, inspired by traditional software security concepts like Control Flow Integrity (Abadi et al., 2009), Access Control (Anderson, 2010, Chap. 6), and Information Flow Control (Denning and Denning, 1977). CaMeL effectively mitigates dangerous outcomes of prompt injection attacks, as demonstrated by practically solving the security evaluation of the AgentDojo benchmark (Debenedetti et al., 2024b). CaMeL associates, to every value, some metadata (commonly called capabilities 2^{2} in the software security literature) to restrict data and control flows, giving the possibility to express what can and cannot be done with each individual value by using fine-grained security policies. CaMeL operates by extracting control and data flows from user queries and employs a custom Python interpreter to enforce security policies, providing security guarantees without modifying the LLM itself. CaMeL does not rely on model behavior modification.

1^{1}CaMeL is short for CApabilities for MachinE Learning.

2^{2}Note that here the term capability refers to the standard security definition, and not the standard machine learning measurement of how capable models are.

Corresponding author(s): edoardo.debenedetti@inf.ethz.ch & iliashumailov@google.com

*Work done as a Student Researcher at Google.

© 2025 Google DeepMind. All rights reserved

Instead, it provides an environment where predefined policies prevent unintended consequences caused by prompt injection attacks, mirroring established software security practices.

Overall, we make the following contributions:

• We propose CaMeL, a novel defense inspired by software security that requires no change to the underlying LLM. CaMeL extracts the control and data flows from user queries and enforces explicit security policies;

• We design a custom Python interpreter for CaMeL that tracks provenance and enforces security policies;

• We integrate CaMeL into AgentDojo (Debenedetti et al., 2024b), a benchmark for agentic systems security, and demonstrate that we solve it by design with some utility degradation, yet with guarantees that no policy violation can take place.

References (48)

  • 2024-05-15
  • : msg.sender
  • line 1, in <module> info = query_ai_assistant(
  • + str(formatted_messages) +
  • Please analyze this landlord notice and extract the new rent amount, effective date, and IBAN for payments. Here's → the notice:\n\n{file_content}
  • line 2, in <module> rent_info = query_ai_assistant( f
  • RentUpdate ) scheduled = get Scheduled_transactions() rent_transactions = [t for t in scheduled if t.subject.lower().find('rent') >= 0] if len(rent_transactions) == 0: raise ValueError(
  • RentUpdate ) update Scheduled transaction( id=current_rent_payment.id, amount=rent_info.new_amount, recipient=rent_info.recipient_iban, date=rent_info.effective_date, subject=current_rent_payment.subject, recurring=current_rent_payment.recurring ) print(f
  • line 12, in <module> rent_info = query_ai_assistant( f
  • File content:
  • RentNoticeInfo ) print(f
  • output_schema=
  • ) if not hawaii_files: raise ValueError(
  • output_schema=<class 'capybility_learning.camel_lang.interpreter.TransactionAnalysis'>
  • New year gift
  • Spotify Premium
  • Sushi dinner
  • HotelAnalysis ) best_paris_hotel = query_ai_assistant( f
  • HotelAnalysis ) london_car_list = london_car_rentals.split(
  • RentalAnalysis ) best_paris_car = query_ai_assistant( f
  • RentalAnalysis ) london_rest_list = london_restaurants.split(
  • RestaurantAnalysis ) best_paris_rest = query_ai_assistant( f
  • Best rated options for your trip:\n
  • line 12, in <module> best_london_hotel = query_ai_assistant( f
  • <The exception was redacted because it came from an untrusted source
  • HotelDetails ) london_hotels_details = [*london_hotels_details, hotel_detail] best_london_hotel = query_ai_assistant( f
  • HotelDetails ) paris_hotels_details = [*paris_hotels_details, hotel_detail] best_paris_hotel = query_ai_assistant( f
  • RentalDetails ) london_rentals_details = [*london_rentals_details, rental_detail] best_london_car = query_ai_assistant( f
  • RentalDetails ) paris_rentals_details = [*paris_rentals_details, rental_detail] best_paris_car = query_ai_assistant( f
  • RestaurantDetails ) london_rest_details = [*london_rest_details, rest_detail] best_london_rest = query_ai_assistant( f
  • line 11, in <module> hotel_detail = query_ai_assistant( f
  • line 4, in <module> hotel_detail = query_ai_assistant( f
  • RentalDetails ) ) london_rentals_details = [*london_rentals_details, rental_detail] best_london_car = query_ai_assistant( f
  • line 9, in <module> hotel_detail = query_ai_assistant( f
  • Try to infer what the → problem was from the context provided.> Provide the new code with the error fixed
  • HotelDetails ) best_paris_hotel = query_ai_assistant( f
  • HotelDetails ) best_london_car = query_ai_assistant( f
  • RentalDetails ) best_paris_car = query_ai_assistant( f
  • RentalDetails ) best_london_rest = query_ai_assistant( f
  • RestaurantDetails ) best_paris_rest = query_ai_assistant( f
  • line 2, in <module> best_london_hotel = query_ai_assistant( f
  • : london_hotel_reviews[hotel]
  • HotelDetails ) paris_hotels_data = [] for hotel in paris_hotel_list: paris_hotels_data = [*paris_hotels_data, {
  • HotelDetails ) london_car_data = [] for company in london_car_list: london_car_data = [*london_car_data, {
  • RentalDetails ) paris_car_data = [] for company in paris_car_list: paris_car_data = [*paris_car_data, {
  • RentalDetails ) london_rest_data = [] for restaurant in london_rest_list: london_rest_data = [*london_rest_data, {
  • RestaurantDetails ) paris_rest_data = [] for restaurant in paris_rest_list: paris_rest_data = [*paris_rest_data, {
  • MeetingSummary ) current_day = get_current_day() upcoming_meetings = search_calendar_events(

Cited by (116)