<?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"><channel><title><![CDATA[Pinnasys AI]]></title><description><![CDATA[Pinnasys AI]]></description><link>https://pinnasysai.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 20 Nov 2026 18:03:34 GMT</lastBuildDate><atom:link href="https://pinnasysai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Testing Non-Deterministic AI Systems Without Losing Your Mind]]></title><description><![CDATA[Learn how to test non-deterministic AI systems using repeated evaluations, outcome-based testing, reliability metrics, and continuous monitoring.]]></description><link>https://pinnasysai.hashnode.dev/testing-non-deterministic-ai-systems-without-losing-your-mind</link><guid isPermaLink="true">https://pinnasysai.hashnode.dev/testing-non-deterministic-ai-systems-without-losing-your-mind</guid><category><![CDATA[AI Systems]]></category><category><![CDATA[AI]]></category><category><![CDATA[ai agents]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Pinnasys]]></dc:creator><pubDate>Thu, 19 Nov 2026 07:36:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a43a4c8b4e912e3c023a983/81836e3c-6f46-4621-b525-4925d231877b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Traditional software testing follows a predictable pattern. Give an application the same input, run the same test, and expect the same output. AI systems do not always work this way.</p>
<p>A large language model might generate different answers to the same question. An AI agent might select different tools or follow different execution paths while completing an identical task.</p>
<p>This makes traditional pass-or-fail testing less useful. Developers cannot always compare outputs word for word and decide whether a test has failed.</p>
<p>The real challenge is understanding which variations are acceptable and which indicate a problem.</p>
<h2><strong>Why Traditional Testing Falls Short</strong></h2>
<p>Traditional software tests often depend on predefined expected outputs. If a function returns something different, the test fails.</p>
<p>With generative AI, this approach can produce misleading results. Consider a customer support assistant answering a password reset question. It might provide correct instructions using different wording across multiple executions.</p>
<p>An exact text comparison would flag these responses as failures, even though both answers are accurate.</p>
<p>The problem goes beyond wording. An AI system might generate an incorrect answer, select an unsuitable tool, or ignore an important instruction while still producing a convincing response.</p>
<p>The <a href="https://hai.stanford.edu/ai-index/2026-ai-index-report/responsible-ai"><u>2026 Stanford AI Index</u></a> recorded 362 reported AI incidents in 2025, compared with 233 in 2024. Although these incidents cover different types of AI-related failures, the increase highlights why evaluation and monitoring cannot be treated as optional.</p>
<p>A useful testing process should distinguish between:</p>
<ul>
<li><strong>Expected variation:</strong> Different wording with the same meaning.</li>
<li><strong>Functional variation:</strong> Different execution paths that achieve the same result.</li>
<li><strong>Unacceptable variation:</strong> Incorrect information, unsupported claims, or broken business rules.</li>
<li><strong>Execution failures:</strong> Tool errors, incomplete workflows, and unexpected behavior.</li>
</ul>
<h2><strong>Understand What Causes AI Outputs to Change</strong></h2>
<p>Before designing test cases, developers need to understand where variation comes from.</p>
<p>Several factors can influence AI behavior:</p>
<ul>
<li><strong>Sampling settings:</strong> Temperature and generation parameters influence token selection.</li>
<li><strong>Prompt changes:</strong> Small differences in instructions can affect responses.</li>
<li><strong>Context history:</strong> Previous messages and retrieved information influence model behavior.</li>
<li><strong>External tools:</strong> APIs and databases may return changing information.</li>
<li><strong>Model updates:</strong> Different model versions can produce different results.</li>
<li><strong>Agent orchestration:</strong> Multi-agent systems may follow different execution paths.</li>
</ul>
<p>Developers should record model versions, prompt versions, generation settings, input context, and tool responses. These details make it easier to investigate unexpected results.</p>
<p>Without this information, identifying whether a failure came from the model, retrieval layer, or external service becomes difficult.</p>
<h2><strong>Build Tests Around Outcomes, Not Exact Responses</strong></h2>
<p>Instead of expecting a specific sentence, define what a successful result should accomplish.</p>
<p>For example, an AI assistant extracting information from invoices should be evaluated on whether it:</p>
<ul>
<li>Identifies the correct invoice number.</li>
<li>Extracts accurate payment amounts and dates.</li>
<li>Recognizes missing information.</li>
<li>Avoids inventing details.</li>
<li>Returns information in the required format.</li>
</ul>
<p>The wording of an explanation can change without affecting the result. However, extracting the wrong payment amount should always count as a failure.</p>
<p>Three evaluation areas are particularly useful:</p>
<p><strong>1. Functional correctness:</strong> Does the system complete the requested task?</p>
<p><strong>2. Semantic correctness:</strong> Does the response communicate the correct meaning?</p>
<p><strong>3. Constraint compliance:</strong> Does the output follow business rules, formatting requirements, and safety restrictions?</p>
<p>This approach is useful when developing <a href="https://www.pinnasys.com/services/ai-development-services"><u>AI-powered applications</u></a>, where outputs often need to satisfy multiple technical and business requirements.</p>
<p>The 2026 Stanford AI Index also highlights a major evaluation challenge. Across 26 models, hallucination rates ranged from 22% to 94% on a benchmark examining how models distinguish facts from beliefs. These figures relate to that specific benchmark, not general-purpose hallucination rates.</p>
<p>The important point is that a model's performance on one evaluation does not guarantee reliable behavior across different tasks.</p>
<h2><strong>Run the Same Tests Multiple Times</strong></h2>
<p>One successful execution does not prove that an AI system is reliable.</p>
<p>Imagine an AI agent processing refund requests. It completes the task correctly during the first test but occasionally selects the wrong policy during subsequent runs.</p>
<p>If testing stops after the first successful execution, these failures remain hidden.</p>
<p>Repeated testing helps developers measure how frequently a system produces correct results.</p>
<p>A practical approach includes:</p>
<ul>
<li>Running important test cases multiple times.</li>
<li>Recording successful and failed executions.</li>
<li>Testing different prompts and context variations.</li>
<li>Measuring task completion rates.</li>
<li>Investigating unexpected changes in results.</li>
</ul>
<p>For example, if an agent completes 92 out of 100 executions successfully, its observed success rate is 92%.</p>
<p>However, this does not establish that the system will maintain a 92% success rate in production. Larger samples, representative test data, and confidence intervals are necessary to understand how reliable that measurement is.</p>
<p>The number of test runs should also reflect the risk involved. A low-impact content assistant and an AI system processing financial transactions should not have identical testing requirements.</p>
<h2><strong>Test Every Stage of AI Agent Execution</strong></h2>
<p>Testing only the final response can hide problems inside an AI workflow.</p>
<p>Consider an agent that retrieves customer information, checks an internal knowledge base, selects a tool, and generates a response.</p>
<p>The final answer might appear correct even when the system retrieved outdated information or selected an unnecessary tool.</p>
<p>Developers should evaluate individual stages:</p>
<table style="min-width:340px"><colgroup><col style="min-width:25px"></col><col style="width:315px"></col></colgroup><tbody><tr><td><p><strong>Workflow stage</strong></p></td><td><p><strong>What to evaluate</strong></p></td></tr><tr><td><p>Input processing</p></td><td><p>Was the request understood correctly?</p></td></tr><tr><td><p>Context retrieval</p></td><td><p>Was relevant information retrieved?</p></td></tr><tr><td><p>Tool selection</p></td><td><p>Was the correct tool selected?</p></td></tr><tr><td><p>Execution</p></td><td><p>Did the tool return valid information?</p></td></tr><tr><td><p>Response generation</p></td><td><p>Was the final answer accurate?</p></td></tr><tr><td><p>Completion</p></td><td><p>Was the task completed successfully?</p></td></tr></tbody></table>

<p>Multi-agent workflows require additional checks. Developers should verify that agents share accurate information, follow their assigned responsibilities, and handle failures without passing incorrect outputs downstream.</p>
<p>This is particularly important when building <a href="https://www.pinnasys.com/services/agentic-ai-services"><u>agentic AI systems</u></a>, where multiple agents coordinate to complete business processes.</p>
<p>Testing individual stages makes it easier to identify whether a failure originated in planning, retrieval, tool execution, or response generation.</p>
<h2><strong>Measure Reliability Instead of Perfect Consistency</strong></h2>
<p>Consistency and accuracy are not the same thing. An AI system can repeatedly produce the same incorrect answer or generate different responses that are all correct.</p>
<p>Developers should therefore measure multiple performance indicators:</p>
<ul>
<li><strong>Task success rate:</strong> Percentage of executions that complete the task correctly.</li>
<li><strong>Output consistency:</strong> Frequency of equivalent results across repeated runs.</li>
<li><strong>Hallucination rate:</strong> Frequency of unsupported or fabricated information.</li>
<li><strong>Tool-call accuracy:</strong> How often the system selects and uses the correct tools.</li>
<li><strong>Latency:</strong> Time required to complete a task.</li>
<li><strong>Failure rate:</strong> Percentage of incomplete or unsuccessful executions.</li>
</ul>
<p>The 2025 DORA research, which included nearly 5,000 technology professionals, found that AI adoption among software development professionals had reached 90%. However, 30% reported having little or no trust in AI.</p>
<p>This gap between adoption and trust makes reliable evaluation particularly important. Teams need measurable evidence of performance rather than relying on positive demonstrations or productivity claims. <a href="https://blog.google/innovation-and-ai/technology/developers-tools/dora-report-2025/"><u>Google Cloud's 2025 DORA findings</u></a> provide further context.</p>
<h2><strong>Make Testing Part of Continuous Monitoring</strong></h2>
<p>AI testing should not stop after deployment. Model updates, changing data sources, prompt modifications, and external API changes can introduce new problems.</p>
<p>Continuous monitoring helps developers identify these issues before they affect more users.</p>
<p>A practical monitoring process should include:</p>
<ul>
<li>Maintaining a collection of previously successful test cases.</li>
<li>Re-running evaluations whenever prompts or models change.</li>
<li>Tracking unusual outputs and production failures.</li>
<li>Reviewing user feedback.</li>
<li>Comparing performance across model versions.</li>
<li>Sending high-impact failures for human review.</li>
</ul>
<p>Regression testing is equally important. Whenever a system changes, previously successful scenarios should be tested again.</p>
<p>Teams should also establish acceptable performance thresholds before deployment. Otherwise, they may notice a decline in quality without knowing when intervention is necessary.</p>
<h2><strong>Final Thoughts</strong></h2>
<p>Testing non-deterministic AI systems is not about eliminating every variation. It is about understanding which variations are acceptable and which indicate a genuine failure.</p>
<p>Developers should focus on measurable outcomes, repeated evaluations, individual execution stages, and continuous monitoring.</p>
<p>A reliable testing strategy should answer three questions:</p>
<ol>
<li>Does the system produce correct results?</li>
<li>Does it maintain acceptable performance across repeated executions?</li>
<li>Can developers identify and investigate failures?</li>
</ol>
<p>The goal is not to make AI behave exactly like traditional software. It is to make its behavior reliable enough for real-world applications.</p>
]]></content:encoded></item><item><title><![CDATA[Your RAG Evaluation Is Measuring the Wrong Thing]]></title><description><![CDATA[Learn how to evaluate RAG systems beyond retrieval accuracy using context relevance, faithfulness, answer quality, and key metrics for production AI.]]></description><link>https://pinnasysai.hashnode.dev/your-rag-evaluation-is-measuring-the-wrong-thing</link><guid isPermaLink="true">https://pinnasysai.hashnode.dev/your-rag-evaluation-is-measuring-the-wrong-thing</guid><dc:creator><![CDATA[Pinnasys]]></dc:creator><pubDate>Mon, 16 Nov 2026 11:24:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a43a4c8b4e912e3c023a983/ef301109-601f-483f-a2dd-070cdf418796.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A RAG application retrieves five relevant documents, generates a fluent answer, and receives a high retrieval score. The evaluation dashboard looks healthy. But when a user asks about a policy exception, the application gives the wrong condition.</p>
<p>The problem is not necessarily the retriever. The language model may have overlooked a sentence, misunderstood a restriction, or combined information from two documents incorrectly.</p>
<p>This is where many RAG evaluations fall short. They measure whether the system found relevant information without checking whether it used that information correctly.</p>
<p>Let's look at what a more useful evaluation process should measure and how to design one for a production RAG application.</p>
<h2><strong>Core Concepts</strong></h2>
<p>Evaluating a RAG system requires looking beyond retrieval accuracy. A few core concepts help explain how retrieved information, selected context, and generated responses affect the quality of the final answer.</p>
<h3><strong>Retrieval quality is only the first checkpoint</strong></h3>
<p>Precision@K, Recall@K, Mean Reciprocal Rank (MRR), and Normalized Discounted Cumulative Gain (NDCG) help evaluate search performance.</p>
<p>They tell you whether relevant passages appear in the retrieved results and how well those results are ranked.</p>
<p>But finding a relevant document does not mean the generated answer will be correct. A retriever can return the right policy while the model overlooks an important exception.</p>
<h3><strong>Context relevance</strong></h3>
<p>Not every retrieved passage contributes to the answer. Context relevance measures whether the information supplied to the model is useful for the question.</p>
<p>Retrieving ten passages when only two contain relevant evidence can increase processing costs and introduce distractions.</p>
<h3><strong>Faithfulness</strong></h3>
<p>Faithfulness checks whether the generated answer is supported by the retrieved context.</p>
<p>If a document allows refunds within 30 days, the model should not claim that customers have 60 days.</p>
<h3><strong>Answer relevance</strong></h3>
<p>A response can be grounded in the correct documents and still fail to address the question.</p>
<p>Answer relevance measures whether the response actually answers what the user asked, rather than simply discussing the same subject.</p>
<p>The <a href="https://arxiv.org/abs/2309.15217"><u>RAGAS research paper</u></a> introduced a reference-free evaluation approach covering context relevance, faithfulness, and answer relevance.</p>
<h2><strong>The Design Problem</strong></h2>
<p>Consider a RAG-based employee support assistant connected to an internal knowledge base containing 500,000 documents.</p>
<p>Employees use it to ask questions about leave policies, reimbursements, insurance, and internal procedures.</p>
<p>The application needs to:</p>
<ul>
<li>Retrieve relevant information from multiple documents.</li>
<li>Handle questions that require combining different policies.</li>
<li>Avoid unsupported answers.</li>
<li>Identify outdated or conflicting information.</li>
<li>Recognize questions that cannot be answered from the knowledge base.</li>
<li>Maintain acceptable response time and evaluation costs.</li>
</ul>
<p>The team currently evaluates the retriever using Recall@5 and Precision@5. Results are strong, but employees still report incorrect answers.</p>
<p><strong>How would you determine whether the problem comes from retrieval, context selection, or generation?</strong></p>
<h2><strong>Questions to Think About</strong></h2>
<ol>
<li>If the correct document appears in the top five results but the answer is incorrect, should retrieval receive a passing score?</li>
<li>How would you evaluate answers that combine information from multiple documents?</li>
<li>What should happen when the knowledge base does not contain the requested information?</li>
<li>Can an LLM reliably evaluate another LLM's response without human validation?</li>
<li>Which measurements should be monitored after deployment?</li>
</ol>
<h2><strong>A Practical Evaluation Approach</strong></h2>
<p>A reliable RAG evaluation process needs more than checking whether the final answer is correct. Each stage should be tested independently to identify gaps in retrieval, context handling, generation, and overall system performance.</p>
<h3><strong>Start with the query, not the score</strong></h3>
<p>Build a test dataset using actual employee questions. Include straightforward requests, multi-document questions, ambiguous queries, policy exceptions, and questions with no supporting answer.</p>
<p>For each query, maintain a reference answer and the relevant source passages where possible.</p>
<p>This creates a way to compare what the system retrieved, what it generated, and what it should have answered.</p>
<h3><strong>Evaluate each stage separately</strong></h3>
<p>For retrieval, measure Recall@K and ranking quality.</p>
<p>For context selection, check whether the retrieved passages contain the evidence needed to answer the question without unnecessary information.</p>
<p>For generation, measure faithfulness and answer relevance. Where reference answers are available, assess factual correctness against them as well.</p>
<p>Do not combine everything into one score too early. Separate measurements help identify the actual source of failure.</p>
<h3><strong>Use automated evaluation carefully</strong></h3>
<p>RAGAS can help automate measurements of context relevance, faithfulness, and answer relevance.</p>
<p>Another useful framework is <a href="https://arxiv.org/abs/2311.09476"><u>ARES</u></a>. Its researchers evaluated RAG systems across eight knowledge-intensive tasks using KILT, SuperGLUE, and AIS datasets. The framework uses trained language-model judges and prediction-powered inference, incorporating a few hundred human-annotated examples to help account for evaluator errors.</p>
<p>This demonstrates an important point: automated evaluation can reduce manual effort, but its reliability still needs to be assessed.</p>
<p>Use human reviewers to validate a representative sample, especially when answers involve policies, financial information, or important business decisions.</p>
<h3><strong>Keep production measurements separate</strong></h3>
<p>An accurate answer is not the only requirement.</p>
<p>Track end-to-end latency, retrieval time, token consumption, cost per request, failure rates, and unnecessary retries.</p>
<p>Also measure whether the system correctly declines to answer when evidence is missing. A reliable RAG application should not invent information to complete every request.</p>
<h2><strong>Model Solution</strong></h2>
<p>A RAG evaluation pipeline should measure each stage separately rather than rely on one overall score.</p>
<ul>
<li><strong>Retrieval:</strong> Use Recall@K, Precision@K, and MRR to check whether the system finds the necessary documents.</li>
<li><strong>Context:</strong> Measure relevance and coverage to ensure important details and exceptions reach the model.</li>
<li><strong>Generation:</strong> Evaluate faithfulness, answer relevance, and agreement with verified answers.</li>
</ul>
<p>Consider an employee asking whether unused leave can be carried forward. If the retriever misses a document explaining exceptions for contract employees, it is a retrieval failure. If both documents are available but the model ignores the exception, the generation stage needs improvement.</p>
<p>Also track latency, token consumption, and cost per request. These metrics reveal operational issues that accuracy scores cannot capture.</p>
<p>Teams building <a href="https://pinnasys.com/services/ai-integration-services"><u>AI integration solutions</u></a> should connect these evaluations with the wider application workflow.</p>
<p>Each failure needs a targeted fix. More retrieval will not solve every RAG problem.</p>
<h2><strong>Conclusion</strong></h2>
<p>A RAG evaluation should tell you more than whether relevant documents appeared in search results. It should show whether the application found sufficient evidence, interpreted it correctly, and delivered an answer that users can trust.</p>
<p>For teams building production AI systems, this requires evaluating the entire pipeline rather than optimizing one metric. At Pinnasys, this distinction is important when engineering RAG solutions for real business workflows.</p>
<p><strong>The goal is not to build a RAG system that retrieves the right documents. It is to build one that uses the right evidence to produce the right answer.</strong></p>
<h2><strong>Try it yourself</strong></h2>
<p>Take 20 questions from an existing RAG application and review the complete retrieval and generation process.</p>
<p>Find cases where the correct document was retrieved, but the final answer was still incorrect. Separate retrieval failures from generation failures, then compare the results before and after making changes.</p>
<p>A small failure-focused evaluation set can reveal problems that a single retrieval score will never show.</p>
]]></content:encoded></item><item><title><![CDATA[Prompt Caching Cost Math: When It Actually Saves You Money]]></title><description><![CDATA[Large language models do not charge only for generating responses. Every request also involves processing input tokens, including system instructions…]]></description><link>https://pinnasysai.hashnode.dev/prompt-caching-cost-math-when-it-actually-saves-you-money</link><guid isPermaLink="true">https://pinnasysai.hashnode.dev/prompt-caching-cost-math-when-it-actually-saves-you-money</guid><dc:creator><![CDATA[Pinnasys]]></dc:creator><pubDate>Tue, 03 Nov 2026 12:50:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a43a4c8b4e912e3c023a983/8bd932e8-dde8-436f-bcb8-84e2b692bb1c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Large language models do not charge only for generating responses. Every request also involves processing input tokens, including system instructions, conversation history, tool definitions, and reference documents. For applications that repeatedly send the same context, these input costs can become a significant part of the API bill.</p>
<p>Consider an AI customer support assistant that processes thousands of conversations daily. Every request includes the same product documentation, company policies, and response instructions. Although the customer question changes, most of the input remains identical.</p>
<p>Prompt caching addresses this inefficiency by allowing an LLM to reuse previously processed prompt prefixes instead of repeatedly processing identical context.</p>
<p>According to <a href="https://developers.openai.com/api/docs/guides/prompt-caching"><u>OpenAI's prompt caching documentation</u></a>, cached input tokens can receive discounts of up to 95%, depending on the model and pricing configuration. However, that does not mean every application will reduce its total API expenditure by 95%.</p>
<p>Cache writes, expiration, minimum token requirements, and request frequency all influence the actual savings.</p>
<p>The important question is not whether prompt caching reduces token prices. It is whether the savings from repeated requests outweigh the cost of creating and maintaining the cache.</p>
<h2><strong>1. Why Repeated Prompt Processing Increases LLM Costs</strong></h2>
<p>Most production LLM applications send considerably more than a user's question.</p>
<p>A typical request may contain:</p>
<ul>
<li>System instructions defining the model's behavior.</li>
<li>Developer instructions establishing application rules.</li>
<li>Tool definitions describing available functions.</li>
<li>Conversation history providing previous interactions.</li>
<li>Retrieved documents containing relevant information.</li>
<li>User messages containing new requests.</li>
</ul>
<p>Some components change with every request, but others remain identical across hundreds or thousands of interactions.</p>
<p>For example, imagine an AI customer support application that sends 30,000 reusable tokens containing product documentation and support policies alongside a 1,000-token customer query.</p>
<p>If the application handles 2,000 requests daily, it processes 60 million reusable input tokens every day.</p>
<p>At a hypothetical input rate of $3 per million tokens, those repeated instructions alone cost $180 daily, or approximately $5,400 monthly.</p>
<p>That expense exists before accounting for user queries, generated responses, retries, or additional model calls.</p>
<p>This is where prompt caching becomes financially relevant. Instead of paying the standard input rate repeatedly, applications can reuse eligible prompt prefixes at a lower cache-read rate.</p>
<h2><strong>2. How Prompt Caching Changes LLM Pricing</strong></h2>
<p><a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching"><strong><u>Prompt caching works</u></strong></a> by preserving previously calculated key-value (KV) states associated with an eligible prompt prefix.</p>
<p>These intermediate states help the model process subsequent tokens. When another request contains the same prefix, the model can reuse the stored states instead of recalculating the entire context.</p>
<p>The billing structure generally involves three categories:</p>
<ul>
<li><strong>Standard input tokens:</strong> Tokens processed at the regular input rate.</li>
<li><strong>Cache write tokens:</strong> Tokens processed and stored when a reusable prefix is created. Depending on the provider, these can cost more than standard input processing.</li>
<li><strong>Cache read tokens:</strong> Previously cached tokens reused by subsequent requests at a discounted rate.</li>
</ul>
<p>Anthropic's published Claude Sonnet 4.6 pricing provides a useful example:</p>
<ol>
<li><strong>Standard input</strong>: $3 per million tokens.</li>
<li><strong>Five-minute cache write:</strong> $3.75 per million tokens.</li>
<li><strong>One-hour cache write</strong>: $6 per million tokens.</li>
<li><strong>Cache read:</strong> $0.30 per million tokens.</li>
</ol>
<p>A five-minute cache write therefore costs 25% more than standard input, while a cache read costs 90% less.</p>
<p>The one-hour cache write costs twice the standard input rate.</p>
<p>These differences matter because the application needs enough successful cache reads to recover the initial write expense.</p>
<h2><strong>3. Calculating the Actual Savings From Prompt Caching</strong></h2>
<p>Let's calculate the financial impact using a practical workload.</p>
<p>Assume an application sends a reusable prompt containing 100,000 tokens across 10 API requests.</p>
<p>For consistency, use Claude Sonnet 4.6 pricing throughout this example.</p>
<p><strong>Without prompt caching</strong></p>
<p>Each request processes 100,000 tokens at $3 per million.</p>
<ul>
<li>Input per request: 100,000 tokens.</li>
<li>Number of requests: 10.</li>
<li>Total input: 1 million tokens.</li>
<li>Total cost: $3.00.</li>
</ul>
<p><strong>With five-minute prompt caching</strong></p>
<p>The first request writes 100,000 tokens into the cache. The remaining nine requests reuse that context.</p>
<ul>
<li>Initial cache write: 100,000 × $3.75 / 1,000,000 = $0.375.</li>
<li>Nine cache reads: 900,000 × $0.30 / 1,000,000 = $0.27.</li>
<li>Total cached input cost: $0.645.</li>
</ul>
<p>The actual savings become:</p>
<p>[<br />Savings = \frac{3.00-0.645}{3.00}\times100<br />]</p>
<p><strong>Result: 78.5% lower input-processing costs.</strong></p>
<p>Now consider a workload that makes 100 requests using the same reusable prefix.</p>
<ul>
<li>Without caching: $30.</li>
<li>With caching: $3.345.</li>
<li>Total savings: approximately 88.85%.</li>
</ul>
<p>The savings increase because the initial cache write is distributed across more requests.</p>
<p>These calculations exclude output tokens and other application expenses. They also assume that every subsequent request successfully reuses the complete cached prefix within its lifetime.</p>
<h2><strong>4. Finding the Break-Even Point</strong></h2>
<p>The break-even point identifies how many requests must reuse a cached prefix before caching becomes financially beneficial.</p>
<p>Using the same Claude Sonnet 4.6 pricing, a five-minute cache write costs 1.25 times the standard input rate, while each cache read costs 0.1 times that rate.</p>
<p>For a 100,000-token prefix:</p>
<table style="min-width:303px"><colgroup><col style="min-width:25px"></col><col style="width:151px"></col><col style="width:127px"></col></colgroup><tbody><tr><td><p><strong>Requests</strong></p></td><td><p><strong>Without caching</strong></p></td><td><p><strong>With caching</strong></p></td></tr><tr><td><p>1</p></td><td><p>$0.30</p></td><td><p>$0.38</p></td></tr><tr><td><p>2</p></td><td><p>$0.60</p></td><td><p>$0.41</p></td></tr><tr><td><p>5</p></td><td><p>$1.50</p></td><td><p>$0.50</p></td></tr><tr><td><p>10</p></td><td><p>$3.00</p></td><td><p>$0.65</p></td></tr><tr><td><p>20</p></td><td><p>$6.00</p></td><td><p>$0.95</p></td></tr></tbody></table>

<p>With a five-minute cache, the first successful reuse makes caching cheaper.</p>
<p>However, a one-hour cache has a different break-even point because its initial write costs twice the standard input rate.</p>
<ul>
<li>One cache write: $0.60.</li>
<li>One cache read: $0.03.</li>
<li>Total after two requests: $0.63.</li>
<li>Standard processing cost after two requests: $0.60.</li>
</ul>
<p>Caching is still slightly more expensive after the first reuse. After two successful cache reads, the total becomes $0.66 instead of $0.90.</p>
<p>Therefore, the one-hour cache becomes economical from the third request.</p>
<p>This demonstrates why developers should evaluate cache duration alongside request frequency rather than selecting the longest available retention period.</p>
<h2><strong>5. When Prompt Caching Delivers the Highest Financial Value</strong></h2>
<p>Prompt caching is most effective when applications repeatedly process large amounts of stable information.</p>
<p>Four common workloads offer particularly strong opportunities.</p>
<p><strong>AI customer support systems</strong></p>
<p>Customer support assistants repeatedly reference product documentation, refund policies, troubleshooting instructions, and response guidelines.</p>
<p>For example, a shared 40,000-token context reused across 1,000 daily interactions creates 40 million potentially reusable input tokens.</p>
<p>At Claude Sonnet 4.6's standard $3 per million input tokens, processing that context without caching would cost $120 daily.</p>
<p>This makes customer support a strong candidate for measuring cache reuse.</p>
<p><strong>Retrieval-Augmented Generation (RAG)</strong></p>
<p>RAG applications combine retrieved documents with user questions. Their system instructions, retrieval rules, and shared reference material may remain stable across multiple requests.</p>
<p>However, dynamically retrieved content should not automatically be cached. Developers need to identify which document prefixes remain identical and which change between requests.</p>
<p><strong>AI coding assistants</strong></p>
<p>Coding assistants frequently reuse repository instructions, project architecture, coding conventions, and tool definitions.</p>
<p>When developers work on the same repository, stable project context can support repeated model calls without requiring the entire prefix to be processed at the standard rate each time.</p>
<p><strong>Multi-step AI agents</strong></p>
<p>Agents often make multiple model calls while planning tasks, selecting tools, validating results, and executing actions.</p>
<p>If these calls share the same instructions and tool definitions, prompt caching can reduce repeated input costs.</p>
<p>For applications connecting multiple models, APIs, and tools, <a href="https://www.pinnasys.com/services/ai-integration-services"><u>AI integration architectures</u></a> can help establish a consistent approach to context management and request handling.</p>
<h2><strong>6. Why Cache Misses Can Eliminate Expected Savings</strong></h2>
<p>A cache hit depends on more than sending similar information. The reusable prompt prefix must satisfy the provider's caching requirements.</p>
<p>For example, OpenAI documents a minimum cacheable prompt length of 1,024 tokens for GPT-5.6 and later models. The minimum varies for earlier models and their configurations.</p>
<p>Anthropic also specifies model-dependent minimums. Claude Sonnet 4.6 requires at least 1,024 tokens, while some other Claude models require 4,096 tokens.</p>
<p>This means a short system prompt may not qualify even if the application sends it repeatedly.</p>
<p>Prompt structure also matters.</p>
<p>Consider two requests:</p>
<p><strong>Request A:</strong></p>
<ul>
<li>System instructions.</li>
<li>Tool definitions.</li>
<li>Product documentation.</li>
<li>Customer question.</li>
</ul>
<p><strong>Request B:</strong></p>
<ul>
<li>System instructions.</li>
<li>Updated timestamp.</li>
<li>Tool definitions.</li>
<li>Product documentation.</li>
<li>Different customer question.</li>
</ul>
<p>The inserted timestamp changes the prefix before the reusable documentation. Consequently, the longer prefix may no longer match the previously cached content.</p>
<p>Developers should:</p>
<ul>
<li>Place stable instructions at the beginning.</li>
<li>Keep reusable tool definitions consistent.</li>
<li>Move dynamic user information toward the end.</li>
<li>Avoid unnecessary changes to shared context.</li>
<li>Monitor actual cache reads instead of assuming repeated requests produce cache hits.</li>
</ul>
<p><a href="https://developers.openai.com/api/docs/guides/prompt-caching"><u>OpenAI also explains that cached prefixes can reduce input-processing</u></a> latency because previously calculated states do not need to be recomputed.</p>
<p>However, actual latency improvements depend on request size, cache availability, and workload characteristics.</p>
<h2><strong>7. How Different LLM Providers Handle Cache Costs</strong></h2>
<p>One serious mistake in cost optimization is assuming that every provider uses identical caching rules.</p>
<p>OpenAI, Anthropic, and Google have different pricing structures, cache lifetimes, and implementation requirements.</p>
<p>For example, OpenAI's GPT-5.6 and later documentation specifies a 30-minute default cache lifetime, with cache writes costing 1.25 times standard input pricing. Its Responses API also supports a 12-hour minimum lifetime at 2.5 times the standard input rate.</p>
<p>Meanwhile, Anthropic's Claude Sonnet 4.6 uses five-minute and one-hour cache-write options, with corresponding write multipliers of 1.25 and 2.</p>
<p>Google's Gemini API introduces another consideration: cached-content storage can be billed separately from token processing. Its applicable paid-tier pricing includes storage at $0.50 per million tokens per hour.</p>
<p>These differences make provider comparisons essential when selecting an LLM for a high-volume application.</p>
<p>A model with a lower standard input price may not necessarily be the cheapest option after accounting for cache writes, cache reads, storage, and actual reuse patterns.</p>
<p>For production applications, <a href="https://www.pinnasys.com/services/ai-development-services"><u>AI development and implementation</u></a> should account for these cost variables alongside performance, reliability, and application requirements.</p>
<h2><strong>8. What to Monitor Before Optimizing Your Cache Strategy</strong></h2>
<p>A lower cache-read price does not automatically translate into a lower total API bill.</p>
<p>Developers should monitor actual usage across different workloads.</p>
<p>Five metrics are particularly useful:</p>
<ul>
<li><strong>Cache-hit ratio:</strong> Percentage of total input tokens billed as cache reads.</li>
<li><strong>Cache-write frequency:</strong> Number of times reusable context is written again.</li>
<li><strong>Cache lifetime:</strong> Whether requests arrive before the stored context expires.</li>
<li><strong>Input cost per request:</strong> Actual standard, write, and read charges.</li>
<li><strong>Output cost per request:</strong> The remaining generation expense that caching does not eliminate.</li>
</ul>
<p>For example, if an application processes 10 million eligible input tokens and 7 million are cache reads, its cache-hit ratio is 70%.</p>
<p>However, a 70% cache-hit ratio does not mean the application saves exactly 70% on its input bill. The actual savings depend on the difference between standard input, cache-write, and cache-read prices.</p>
<p><a href="https://developers.openai.com/api/docs/guides/prompt-caching"><u>OpenAI's prompt caching documentation</u></a> also recommends monitoring cached-token usage, cache-write tokens, and cache-hit rates to identify opportunities for improving reuse.</p>
<p>The objective should be to measure the actual cost per request rather than relying on a theoretical caching discount.</p>
<h2><strong>Conclusion</strong></h2>
<p>Prompt caching becomes financially valuable when an application repeatedly sends large, predictable prompt prefixes within the cache's available lifetime.</p>
<p>The calculations show that even a single successful reuse can justify a five-minute cache write under the Claude Sonnet 4.6 pricing example. Longer cache durations require more reuse to recover their higher initial costs.</p>
<p>However, cache-hit rates, token thresholds, prompt consistency, expiration, and provider-specific pricing all influence the final result.</p>
<p>The most reliable approach is to measure actual cache writes and reads, calculate the cost per request, and compare it with the uncached baseline.</p>
<p><strong>The objective is not to cache every prompt. It is to identify which repeated computations are expensive enough to justify caching.</strong></p>
<p><br /><br /><br /><br /><br /><br /><br /><br /><br />\</p>
]]></content:encoded></item><item><title><![CDATA[Claude Tool Use: What to Do When Tool Calls Go Wrong]]></title><description><![CDATA[Claude tool use is one of the most powerful capabilities in the Anthropic API, and one of the most fragile when left unguarded. When Claude calls a tool…]]></description><link>https://pinnasysai.hashnode.dev/claude-tool-use-what-to-do-when-tool-calls-go-wrong</link><guid isPermaLink="true">https://pinnasysai.hashnode.dev/claude-tool-use-what-to-do-when-tool-calls-go-wrong</guid><dc:creator><![CDATA[Pinnasys]]></dc:creator><pubDate>Thu, 03 Sep 2026 06:08:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a43a4c8b4e912e3c023a983/5d856edf-bf6b-4d5c-9267-282cf6975ab9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Introduction</strong></h2>
<p>Claude tool use is one of the most powerful capabilities in the Anthropic API, and one of the most fragile when left unguarded. When Claude calls a tool correctly, and the tool returns clean data, the workflow runs exactly as designed. When the call comes back wrong, the consequences depend entirely on whether your system was built to catch it.</p>
<p>The problem is that failures are not always obvious. Claude might select the right tool but pass a parameter with the wrong type. It might receive a malformed response and continue reasoning as if the data were valid. In multi-step agentic workflows, as <a href="https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents">Anthropic's own engineering notes confirm</a>, mistakes compound across turns; an early error in a five-step workflow does not stay contained to step one.</p>
<p>This tutorial walks through the most common tool-calling failure modes, how to detect them, and the implementation patterns that keep Claude-powered systems reliable under real production conditions.</p>
<h2><strong>How Claude Uses Tools</strong></h2>
<p>Before covering what goes wrong, it helps to understand the mechanism. When you define tools for Claude, you are passing a schema that describes what each tool does, what parameters it accepts, and what types those parameters expect. Claude reads those descriptions, decides which tool fits the current task, constructs a tool call with the appropriate arguments, and returns the call to your application for execution.</p>
<p>Your application runs the tool, gets a result, and passes that result back to Claude as a tool result message. Claude then uses that result to decide what to do next, whether that is calling another tool, asking a clarifying question, or generating a final response.</p>
<p>The key thing to understand is that Claude does not execute the tool itself. Your code does. That boundary is where most of the reliability engineering needs to happen.</p>
<h2><strong>Common Tool-Calling Errors</strong></h2>
<p>Claude tools can fail for several reasons, from incorrect parameters and tool selection to malformed responses and errors that compound across multi-step workflows.</p>
<h3><strong>Wrong or Missing Parameters</strong></h3>
<p>The most frequent failure type. Claude may omit an optional parameter that your tool actually requires in practice, or pass a value in the wrong format: a string where your function expects an integer, a date in the wrong format, or a nested object where a flat key was expected.</p>
<p><a href="https://openai.com/index/introducing-structured-outputs-in-the-api/">OpenAI's structured outputs research</a> demonstrated how significant this problem is: earlier models scored below 40% on complex schema-following tasks, while models with constrained output methods reached 100%. The gap shows that parameter reliability is a real engineering concern, not a theoretical one, regardless of which model you use.</p>
<p><strong>What to do:</strong> Validate every tool call against your schema before execution. Do not assume Claude's output matches the type you defined; check it explicitly in your application layer.</p>
<h3><strong>Incorrect Tool Selection</strong></h3>
<p>Claude occasionally picks a tool that is close to the right one but not exactly right, particularly when two tools have overlapping purposes or ambiguous descriptions. A get_customer_record tool and a get_account_details tool might both seem reasonable for a given query if their descriptions are not specific enough.</p>
<p><a href="https://www.anthropic.com/engineering/writing-tools-for-agents">Anthropic's research on writing effective tools for agents</a> points directly at this cause: tool descriptions that are vague or redundant increase the probability of incorrect selection. The description is not documentation for a human reader; it is the signal Claude uses to decide which tool to invoke.</p>
<p><strong>What to do:</strong> Write tool descriptions that clarify when the tool should not be used, not just when it should. If two tools overlap, make the boundary between them explicit in the description.</p>
<h3><strong>Malformed or Empty Tool Responses</strong></h3>
<p>Sometimes the tool call is correct, and Claude's parameters are valid, but the tool itself returns something unexpected: an empty array, a null field, an HTTP error, or a payload that does not match the schema your prompt assumes. If you pass that result back to Claude without validation, Claude will try to reason about bad data and often produce a confident but incorrect next step.</p>
<p><strong>What to do:</strong> Treat every tool response as untrusted input. Check for nulls, empty results, and error states before passing the result back into the conversation. Return a structured error message to Claude instead of raw failure output.</p>
<h3><strong>Compounding Errors in Multi-Step Workflows</strong></h3>
<p>Single tool call failures are manageable. The harder problem is what <a href="https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents">Anthropic describes</a> as error propagation: in agentic workflows where Claude operates across multiple turns, calling tools, changing state, and adapting to intermediate results, an incorrect assumption at step two can corrupt every decision that follows.</p>
<p>The <a href="https://gorilla.cs.berkeley.edu/leaderboard.html">Berkeley Function Calling Leaderboard</a> evaluates models specifically on multi-turn and parallel tool use, and the performance gap between single-turn and multi-step scenarios is significant across all models tested. Complexity compounds the failure rate in a way that single-turn benchmarks do not reveal.</p>
<p><strong>What to do:</strong> Add checkpoints between steps in multi-turn workflows. Validate state at each stage rather than only at the final output.</p>
<h2><strong>How to Detect a Bad Tool Call</strong></h2>
<p>Detection happens at three points in the tool-use loop:</p>
<ul>
<li><p><strong>Before execution:</strong> Validate the tool call Claude returned against your schema. Check that required fields are present, types match, and values fall within expected ranges. Reject the call and return a structured error message to Claude before anything runs.</p>
</li>
<li><p><strong>After tool execution:</strong> Validate the tool's response before passing it back. Check for empty results, error codes, and structural mismatches. If the tool returned an error, tell Claude explicitly: "The tool returned an error: [error detail]. Please review the parameters and try again."</p>
</li>
<li><p><strong>At the workflow level:</strong> Log every tool call and response. In multi-step workflows, add a state validation step between major stages. If the accumulated state looks inconsistent, surface it to a human reviewer rather than letting the workflow continue.</p>
</li>
</ul>
<h2><strong>Handling Tool-Call Errors in Practice</strong></h2>
<p>The core pattern is straightforward: validate, then decide whether to retry, fallback, or escalate.</p>
<ul>
<li><p><strong>Retry with corrected context:</strong> When Claude passes a wrong parameter type, return a clear error message that describes what was wrong and what was expected. Claude will generally self-correct on a retry if the error message is specific. Vague errors like "invalid input" produce vague corrections.</p>
</li>
<li><p><strong>Fallback to a simpler tool:</strong> If a complex tool consistently fails for a class of inputs, route those inputs to a simpler, more constrained tool rather than retrying indefinitely. Build the fallback logic into your application layer, not into the prompt.</p>
</li>
<li><p><strong>Escalate to a human:</strong> For high-stakes workflows, define explicit escalation conditions. If a tool call fails twice, or if the tool returns data that contradicts expected state, route the task to a human reviewer. Agentic automation should reduce human involvement on routine cases, not eliminate human judgment on edge cases.</p>
</li>
</ul>
<h2><strong>Testing Tool Calls Before Production</strong></h2>
<p>A tool-calling system that works in development can encounter unexpected edge cases in production. Claude tools often fail when real-world workflows introduce conditions that testing didn’t anticipate.</p>
<p>Test against the real failure modes, not just the happy path:</p>
<ul>
<li><p>Pass deliberately malformed parameters and confirm your validation layer catches them</p>
</li>
<li><p>Return empty, null, and error responses from your tools and check how Claude responds to each</p>
</li>
<li><p>Run multi-step workflows with injected failures at different stages to see whether errors propagate or get caught</p>
</li>
<li><p>Test with the full range of user inputs your system will actually receive, not just the clean examples you wrote the prompt around</p>
</li>
</ul>
<p><a href="https://www.anthropic.com/engineering/writing-tools-for-agents">Anthropic's engineering guidance</a> recommends treating tool evaluation as an iterative cycle: prototype the tool, run the agent against it, observe where it fails, improve the description or schema, and repeat. The description and the schema are not static artifacts; they are part of the system that needs testing and refinement.</p>
<h2><strong>Best Practices for Reliable Claude Tool Use</strong></h2>
<p>Reliable Claude tools depend on clear instructions, strong validation, and well-defined recovery paths.</p>
<ul>
<li><p>Write tool descriptions that include when not to use the tool, not just when to use it</p>
</li>
<li><p>Validate every tool call input before execution and every tool response before passing it back to Claude</p>
</li>
<li><p>Return structured, specific error messages rather than raw failure output; Claude corrects more accurately from precise feedback</p>
</li>
<li><p>Add state validation checkpoints in multi-step workflows so errors are caught early rather than compounding</p>
</li>
<li><p>Log all tool calls and responses so failures can be diagnosed and patterns identified</p>
</li>
<li><p>Define human escalation conditions explicitly and build them into the application layer, not the prompt</p>
</li>
</ul>
<h2><strong>Conclusion</strong></h2>
<p>Claude tool use works well when the system around it is built to handle the cases where it does not. The tool calls that come back wrong are predictable: wrong parameters, incorrect tool selection, malformed responses, and compounding errors in multi-step workflows. Each failure mode has a corresponding detection and handling pattern, and none of them require exotic engineering.</p>
<p>The systems that hold up in production are the ones where validation, error handling, and human escalation were designed in from the start, not added later when something broke. Whether you are building a simple single-tool workflow or a complex multi-agent pipeline, the reliability work is the same: validate at every boundary, test against real failure modes, and keep a human in the loop for the decisions that matter.</p>
<p>Pinnasys builds and runs production-grade AI agent systems for teams who need tool-use reliability at scale, not just a working demo. If your agentic build needs a stronger foundation, <a href="https://www.pinnasys.com/services/ai-development-services">our AI development practice</a> is a practical starting point.</p>
]]></content:encoded></item></channel></rss>