Elizabeth Fuentes on Halting AI Agent Hallucinations: 5 Code-Centric Methods

Elizabeth Fuentes Leone of AWS presents five code-based techniques to combat AI agent hallucinations, focusing on semantic tool selection, Graph-RAG, multi-agent validation, neuro-symbolic guardrails, and runtime steering.

8 min read
Elizabeth Fuentes Leone presenting on stopping AI agent hallucinations at AWS event
AI Engineer
Visual TL;DR
AI Agent HallucinationsDriver
From the article 9+ mentionsIn the rapidly evolving world of AI, the challenge of agent hallucinations remains a significant hurdle, impacting both operational costs and the reliability of AI applications.
Elizabeth Fuentes LeoneCore
From the article 9+ mentionsElizabeth Fuentes Leone, a Developer Advocate for Amazon (NASDAQ:AMZN) Web Services (AWS) specializing in agentic applications, recently outlined five advanced techniques to combat these issues.
Code-Centric MethodsContext
five advanced techniques beyond prompt engineering for developers
From the articleBy moving beyond prompt-based fixes and integrating these five code-centric techniques, developers can build more reliable, cost-effective, and robust AI agents, ready for real-world production challenges.
Semantic Tool SelectionContext
AI agents choose appropriate tools based on query meaning
From the article 2 mentionsThe first technique, Semantic Tool Selection, addresses the issue of excessive context window usage.
Graph-RAGContext
retrieval augmented generation using knowledge graphs for precision
From the article 2 mentionsGraph-RAG offers a solution by building a knowledge graph from documents, representing entities and relationships.
Multi-Agent ValidationContext
multiple AI agents cross-verify information for accuracy
From the articleTo counter this, a multi-agent validation system can be implemented.
Neuro-Symbolic GuardrailsContext
combining neural networks with symbolic rules to prevent errors
From the article 2 mentionsNeuro-Symbolic Guardrails achieve this by placing rules in Python code, making them inescapable for the model.
Accurate, Efficient AIOutcome
building more reliable and cost-effective AI agent applications
From the articleHer presentation, aimed at developers and tech enthusiasts, emphasizes code-based solutions over mere prompt engineering, offering practical pathways to building more accurate and efficient AI agents.
Contents(8)

In the rapidly evolving world of AI, the challenge of agent hallucinations remains a significant hurdle, impacting both operational costs and the reliability of AI applications. Elizabeth Fuentes Leone, a Developer Advocate for Amazon (NASDAQ:AMZN) Web Services (AWS) specializing in agentic applications, recently outlined five advanced techniques to combat these issues. Her presentation, aimed at developers and tech enthusiasts, emphasizes code-based solutions over mere prompt engineering, offering practical pathways to building more accurate and efficient AI agents.

Elizabeth Fuentes on Halting AI Agent Hallucinations: 5 Code-Centric Methods - AI Engineer
Elizabeth Fuentes on Halting AI Agent Hallucinations: 5 Code-Centric Methods, from AI Engineer

Who Is Elizabeth Fuentes Leone

Elizabeth Fuentes Leone serves as a Developer Advocate at AWS, where her work focuses on agentic applications. She is instrumental in educating the developer community on best practices and advanced techniques for building robust AI systems. Her expertise lies in translating complex AI challenges into actionable code-level solutions, particularly within open-source frameworks like Strands Agent, which AWS maintains.

The Dual Problem: Cost and Accuracy

Fuentes Leone opened by highlighting the core problems associated with AI agent hallucinations: token waste and compromised accuracy. "Every time your AI agent responds, you are paying for the words going in and the words coming out. And your bill, you will see those calling tokens," she explained. More tokens mean higher costs, and if the input or process is flawed, the agent begins to hallucinate, leading to inaccurate answers and further wasted resources. The five techniques Fuentes Leone presented aim to reduce token waste, improve accuracy, and catch failures before they reach the user, all through code changes rather than prompt adjustments.

Technique 1: Semantic Tool Selection

The first technique, Semantic Tool Selection, addresses the issue of excessive context window usage. Fuentes Leone demonstrated a travel agent with 29 tools (flights, hotels, payments, cancellations, etc.). In a traditional setup, every user query sends the descriptions of all 29 tools into the context window, consuming thousands of tokens per call, even if only a few tools are relevant. Each tool's schema alone can range from 70 to 200 tokens.

By implementing a semantic tool selection mechanism, the agent can filter tools based on query relevance. Fuentes Leone showed how this reduced token usage from thousands to under 300 by only presenting the three most relevant tools to the model. This not only cuts costs but also improves accuracy by preventing the model from getting confused by an overly broad set of options.

For agents with memory, this technique is even more critical. As conversations grow, the accumulated context further inflates token count. Dynamic tool swapping ensures that only currently relevant tools are in context, clearing and re-registering tools as needed to maintain conversational flow without spiraling costs.

Technique 2: Graph-RAG for Precise Answers

Traditional Retrieval Augmented Generation (RAG) works well for open-ended questions but struggles with precise queries requiring aggregation, counting, or multi-hop reasoning. Fuentes Leone illustrated this with questions like "What is the average rating across all hotels in Paris?" or "How many hotels have a swimming pool?" Vector search in standard RAG often returns a sample of documents, leading the model to guess or estimate, presenting these estimates as facts. "Vector search always returns something, even when nothing is truly relevant," she noted.

Graph-RAG offers a solution by building a knowledge graph from documents, representing entities and relationships. Instead of retrieving text chunks, the model writes a Cypher query (Neo4j's query language) to traverse this structured graph. This allows the agent to compute verifiable answers directly from the entire dataset, rather than sampling and estimating. Fuentes Leone demonstrated how Graph-RAG provided exact counts and averages, even correctly identifying that there were no hotels in Antarctica, avoiding the fabricated answers common with traditional RAG.

Technique 3: Multi-Agent Validation

A common pitfall in AI agent development is silent failure. An agent might call a tool, receive an error, rationalize it, and then return a fabricated success message to the user. "The agent acts and validates its own output in the same loop, no separation, no second opinion," Fuentes Leone explained. This leads to users believing a task was completed when it wasn't.

To counter this, a multi-agent validation system can be implemented. Using Strands Agent's built-in Swarm class, Fuentes Leone showed a three-agent sequence: an executor, a validator, and a critic. The executor attempts the task, the validator checks the response for errors, and the critic approves or rejects it. If an error occurs, the critic rejects the response, ensuring the user receives a clear failure notification instead of a fabricated success. This separation of concerns prevents the agent from self-rationalizing its failures.

Technique 4: Neuro-Symbolic Guardrails

Relying solely on system prompts for rules (e.g., "maximum 10 guests per reservation") is often insufficient. "Prompts probably are suggestions, not constraints," Fuentes Leone stated. The probabilistic nature of large language models means they might ignore these suggestions. For true enforcement, rules must be embedded in code.

Neuro-Symbolic Guardrails achieve this by placing rules in Python code, making them inescapable for the model. Strands Agent uses 'hooks', functions automatically called at specific points in the agent's loop, such as right before a tool executes. Fuentes Leone demonstrated rules like "check-in must be before check-out," "maximum 10 guests per booking," and "payment before confirm." If a rule fails, the hook cancels the tool call. This ensures hard constraints are met, providing deterministic behavior where probabilistic prompts fail.

Technique 5: Runtime Steering

While neuro-symbolic guardrails are excellent for hard constraints, sometimes a rule is 'soft,' meaning the agent should adjust and continue rather than blocking entirely. For example, if a room fits four guests but a group of six wants to book, the agent could steer towards booking two rooms instead of blocking the request. "You don't want to block everything. Probably you want the agent to find an option and complete the task," Fuentes Leone said.

Runtime Steering, implemented via the Agent Control SDK, allows agents to self-correct. Instead of hard blocks, rules are registered on a local server via API. When a rule fires, the agent is steered to find an alternative solution and complete the task without user intervention. This approach offers operational flexibility: changing a rule involves updating the API, not redeploying the entire agent code.

Production Patterns with Amazon Bedrock Agent Core

Fuentes Leone concluded by outlining how these techniques can be deployed in production using Amazon (NASDAQ:AMZN) Bedrock Agent Core. This managed service provides the runtime environment, gateway, memory (short-term and long-term), and observability, eliminating the need for developers to manage infrastructure. Strands Agent, or any other framework, can run within this runtime. Gateway rules automatically route tool calls to Lambda functions, and steering rules are stored in DynamoDB, allowing for live updates without redeployment. For graph databases, Neo4j AuraDB offers an external, scalable solution.

By moving beyond prompt-based fixes and integrating these five code-centric techniques, developers can build more reliable, cost-effective, and robust AI agents, ready for real-world production challenges.

© 2026 StartupHub.ai. All rights reserved. Do not enter, scrape, copy, reproduce, or republish this article in whole or in part. Use as input to AI training, fine-tuning, retrieval-augmented generation, or any machine-learning system is prohibited without written license. Substantially-similar derivative works will be pursued to the fullest extent of applicable copyright, database, and computer-misuse laws. See our terms.