<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Carlos Bertoncelli on Medium]]></title>
        <description><![CDATA[Stories by Carlos Bertoncelli on Medium]]></description>
        <link>https://medium.com/@cabertoncelli?source=rss-18f12bf5af6b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*FKywW1ZdMwAdqXAsAw3oRQ.jpeg</url>
            <title>Stories by Carlos Bertoncelli on Medium</title>
            <link>https://medium.com/@cabertoncelli?source=rss-18f12bf5af6b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:07:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cabertoncelli/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Avoid Hallucination in Agentic LLM Workflows]]></title>
            <link>https://medium.com/@cabertoncelli/how-to-avoid-hallucination-in-agentic-llm-workflows-6b6bb4d06a2a?source=rss-18f12bf5af6b------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b6bb4d06a2a</guid>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[llm-applications]]></category>
            <dc:creator><![CDATA[Carlos Bertoncelli]]></dc:creator>
            <pubDate>Tue, 26 May 2026 20:11:20 GMT</pubDate>
            <atom:updated>2026-05-27T13:49:44.645Z</atom:updated>
            <content:encoded><![CDATA[<p><em>As language models take on longer, more autonomous tasks, the risk of hallucination compounds at every step. Here is a rigorous guide to mitigate it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2X0iW7_nVklG_0JItRwbNw.png" /></figure><h3>Why hallucination is more dangerous in agentic settings</h3><p>In a simple chatbot, a hallucination is an embarrassment: the model invents a fact, the user notices, the conversation resets. In an agentic workflow, a hallucination is a cascade. The model acts on its fabrication, writes a file, calls an API, modifies a database, sends an email. Downstream nodes inherit the error as if it were ground truth. By the time a human reviews the output, the damage is compounded through five or ten reasoning steps.</p><p>Agentic LLMs compound hallucination risk in three structural ways. First, they operate over long contexts where facts introduced early drift from attention. Second, they must plan ahead, which requires the model to generate intermediate reasoning steps, each of which is a new surface for fabrication. Third, they interact with external tools, and tool outputs can themselves be misread or silently truncated, producing a secondary layer of hallucination downstream.</p><p><strong>Why this matters now?</strong></p><p>The deployment of LLM agents in production settings for code generation, data analysis, customer service automation, and scientific research means that hallucination is no longer just a quality problem. It is a reliability and safety problem with real-world consequences.</p><h3>A map of hallucination types in agentic contexts</h3><p>Identifying which type of hallucination you are encountering is the prerequisite to choosing the right mitigation. Applying retrieval-augmented generation to a tool misuse problem, or adding self-consistency prompts to a context collapse problem, will yield only marginal gains.</p><p>Not all hallucinations are alike. Conflating them leads to solutions that address the wrong failure mode. In agentic workflows, four types are most prevalent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-tfss-830-e1qoItSKdcFA.png" /></figure><h3>Ground every reasoning step in retrieved evidence</h3><p>Before the model acts on any factual claim, prompt it to write a citation block referencing the retrieved chunk by index. If no citation exists, the model must say so explicitly rather than proceeding. This simple constraint functions as a forcing mechanism that brings hallucinations to the surface before they can influence downstream actions.</p><p>For structured data like APIs, database schemas, or code libraries, prefer injecting the ground-truth schema directly into the prompt over relying on the model’s parametric memory. API endpoint names change, function signatures evolve, and model training data goes stale. A live schema fetch costs latency, and a wrong API call costs integrity.</p><p>Effective agentic RAG requires step-level retrieval, not just an initial document fetch. Each planning step should explicitly query a knowledge source before the model reasons over it. This means designing your workflow so that the planner emits a retrieval query as part of its output, a retrieval node executes it, and the result is injected into the next reasoning step as a constrained context block.</p><p>Retrieval-augmented generation (RAG) is the most battle-tested approach to factual hallucination. The principle: instead of asking the model to recall, you supply the facts. But in agentic workflows, naive RAG breaks down because the agent must retrieve multiple times, over multiple steps, against a context that is constantly changing.</p><h3>Use structured outputs to make hallucination detectable</h3><p>Free-form text is a hallucination’s natural habitat. When a model produces unstructured prose, errors are easy to embed and hard to catch. Structured outputs, whether JSON schemas, typed function calls, or constrained grammars, force the model to commit to a specific shape that can be validated.</p><p>In agentic workflows, this means defining explicit output schemas for each node in your pipeline. A planning node produces a plan object with a fixed set of fields. A tool-calling node produces a typed call with validated parameters. A summarization node produces a structured summary with referenced source IDs. Each of these can be validated programmatically before the output is passed downstream.</p><blockquote>Key technique: <strong>schema-constrained generation</strong></blockquote><blockquote>Most modern LLM APIs support JSON mode or function calling with schema enforcement. Use these natively where possible. For open-source models, tools like <a href="https://github.com/dottxt-ai/outlines">Outlines</a> and <a href="https://github.com/guidance-ai/guidance">Guidance</a> allow grammar-constrained decoding that can reduce structural hallucination by an order of magnitude.</blockquote><p>Schema validation alone is not sufficient. A model can produce a structurally valid JSON object with semantically wrong content. Pair structural validation with semantic checks: are the referenced IDs real? Does the date fall within a plausible range? Does the URL return a 200 status? These runtime assertions are your second line of defense.</p><h3>Decompose tasks to minimize reasoning surface area</h3><p>Every reasoning step a model takes is an opportunity for hallucination. Long, complex, multi-part instructions ask the model to hold too many constraints simultaneously. Decomposition is the architectural discipline of making each step small enough that the model is unlikely to go wrong.</p><p>Effective decomposition in agentic workflows follows a few principles:</p><ul><li>One instruction per step. A node that is asked to both plan and execute will frequently collapse the two, skipping planning and hallucinating a plausible-looking shortcut.</li><li>Separate retrieval from reasoning. Never ask the model to simultaneously find information and decide what to do with it. Retrieve first, then reason over a fixed, grounded context.</li><li>Checkpoint after each step. Before passing output downstream, a lightweight verification layer checks that the output satisfies the step’s expected postconditions.</li><li>Limit chain depth. Research consistently shows that hallucination probability increases non-linearly with chain length. If a task requires more than five or six chained steps, consider breaking it into separate sub-workflows with human checkpoints between them.</li></ul><h3>Implement self-consistency and multi-agent verification</h3><p>Self-consistency and multi-agent verification is a technique to reduce hallucination-induced failures in agentic AI workflows.</p><p>A single model pass is a single sample from a probability distribution, meaning it is inherently unreliable for high-stakes tasks. Models are also better at detecting errors in text they did not produce than in their own output, which makes separating generation from verification a powerful strategy.</p><p>The approach combines two complementary mechanisms. Self-consistency sampling generates multiple candidate answers and selects the most common one, which works remarkably well for factual tasks. Multi-agent verification adds a second model that acts as a critic, given the first model’s output and the original task specification, prompted specifically to find errors, hallucinations, or inconsistencies rather than to improve the answer.</p><p>For high-stakes workflows, a three-agent pattern works well: a generator produces the initial output, a verifier checks for hallucinations and inconsistencies, and a reconciler synthesizes both into a final corrected result. Each agent runs independently. The verifier should answer specific binary yes/no questions rather than give open-ended answers, as they are easier to act on:</p><ul><li>Does every factual claim have a cited source?</li><li>Are all tool calls syntactically valid?</li><li>Does the plan achieve the stated goal?</li><li>Does anything contradict the provided context?</li></ul><p>In practice, apply self-consistency to critical planning or decision steps by running them multiple times with independent samples and reconciling outputs before proceeding. Design the verifier prompt around specific questions and use binary outputs to make verification results directly actionable. The tradeoff is added latency, but the reliability gains justify it for production workflows where hallucination failures are costly.</p><h3>Design prompts that make uncertainty explicit</h3><p>Language models are trained to produce fluent, confident-sounding text. This is precisely what makes hallucination hard to detect: the fabricated claim sounds exactly like a verified one. Prompt engineering can partially counteract this by instructing the model to signal its uncertainty explicitly.</p><p>Concretely, this means adding instructions like: “If you are not certain of a fact, say so using the phrase ‘I am not certain, but…’ rather than stating it as fact.” or “If a required piece of information is not in the provided context, state that it is missing rather than inferring it.” These instructions do not eliminate hallucination, but they make it auditable: uncertain claims can be flagged for human review or retrieval fallback before being passed to the next step.</p><p>Calibration probes are another tool. Before a critical step, ask the model to rate its confidence on a defined scale and briefly explain why. Low confidence scores trigger a fallback path, such as human review or a retrieval step, rather than allowing the workflow to proceed on a shaky foundation. Combined with empirical calibration data collected over production runs, this can be tuned to a useful operating point.</p><h3>Instrument your workflows for hallucination observability</h3><p>You cannot improve what you cannot see. Most agentic workflow failures are invisible until they produce a catastrophic output. Instrumentation, the practice of logging and monitoring each step’s inputs, outputs, and metadata, is the foundation of any serious hallucination reduction program.</p><p>A basic instrumentation stack for agentic workflows includes:</p><ul><li>Step-level traces: every prompt, model call, and output is logged with timestamps and model identifiers, enabling post-hoc analysis of where errors entered the chain.</li><li>Assertion logging: every programmatic validation check records its result, making it easy to identify which checks are catching errors and which are never triggered.</li><li>Confidence metadata: if you are eliciting confidence scores, log them alongside the outputs they qualify so you can correlate confidence with actual error rates over time.</li><li>Hallucination labels: when errors are discovered in production, a lightweight labeling workflow that tags which step produced the error and what type it was builds a dataset for systematic improvement.</li></ul><blockquote>Tools worth evaluating include LangSmith, Phoenix by Arize, and Weights &amp; Biases Weave. Each provides step-level tracing for LLM pipelines, with different trade-offs in observability, customization, and integration depth. For teams with self-hosted or vendor-neutral requirements, <a href="https://opentelemetry.io/">OpenTelemetry</a> combined with a custom schema is a strong option, offering flexibility while minimizing vendor lock-in.</blockquote><h3>A layered defense architecture</h3><p>No single technique eliminates hallucination. The state of the art is a layered defense: multiple mitigations applied at different points in the workflow, so that an error which slips through one layer is caught by the next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_a5YqxI5QfLw9EyQdo7YGg.png" /></figure><p>The organizations shipping the most reliable agentic systems today do not treat hallucination as a model problem to be solved upstream. They treat it as a systems engineering problem, designing workflows where hallucination can happen but cannot do serious damage, and where every failure makes the system smarter for the next run.</p><p>The techniques described here are not theoretical. They are the current engineering best practices for teams building production agentic systems. Each one has a cost, in latency, complexity, or compute, and the right combination depends on your risk tolerance, task domain, and scale. Start with grounding and structured outputs, which offer the highest reliability improvement per unit of complexity. Add verification layers as stakes increase. And invest in observability from day one: it is the only way to know whether your mitigations are actually working.</p><p><strong>References:</strong></p><ul><li><em>Mitigating Hallucination in Large Language Models: An Application-Oriented Survey on RAG, Reasoning, and Agentic Systems</em>, Yihan Li et al., <a href="https://arxiv.org/abs/2510.24476">https://arxiv.org/abs/2510.24476</a></li><li><em>Hallucination Mitigation using Agentic AI Natural Language-Based Frameworks</em>, Diego Gosmar &amp; Deborah A. Dahl, <a href="https://arxiv.org/pdf/2501.13946">https://arxiv.org/pdf/2501.13946</a></li><li><em>Large Language Models Hallucination: A Comprehensive Survey</em>, Multiple Authors, <a href="https://arxiv.org/html/2510.06265v2">https://arxiv.org/html/2510.06265v2</a></li><li><em>InEx: Hallucination Mitigation via Introspection and Cross-Modal Multi-Agent Collaboration</em>, Multiple Authors, <a href="https://arxiv.org/pdf/2512.02981">https://arxiv.org/pdf/2512.02981</a></li><li><em>Reasoning Aware Self-Consistency: Leveraging Reasoning Paths for Efficient LLM Sampling</em>, Multiple Authors, <a href="https://arxiv.org/pdf/2408.17017">https://arxiv.org/pdf/2408.17017</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b6bb4d06a2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>