Skip to main content

Posts

Solving JSON Parsing Errors with Local LLM Agents (Ollama & Llama 3)

  If you are building autonomous agents with local LLMs like Llama 3 (via Ollama) and LangChain, you have likely encountered the infamous   OutputParserException   or   JSONDecodeError . The scenario is almost always the same: You prompt your agent to return structured data for a tool call. The model generates 99% correct output, but fails on a trailing comma, a missing quote, or by wrapping the JSON in Markdown backticks. Your agent crashes, and your workflow breaks. While GPT-4 is generally compliant with strict JSON syntax, quantized local models (like Llama 3 8B) trade precision for speed and memory efficiency. This article details the root cause of these parsing failures and provides a production-grade, code-first solution to sanitize and parse "dirty" JSON from local models using LangChain. The Root Cause: Why Llama 3 Struggles with Strict JSON To fix the problem, we must understand why it happens. The issue usually stems from three distinct behaviors in local ...

Handling "requires_action" Stalls in OpenAI Assistants API

  You have configured your Assistant, defined your function schemas, and initiated a run. The Assistant correctly identifies the intent and decides to call a function. However, the process never completes. The Run status hangs indefinitely in   requires_action , and the final response is never generated. This "zombie run" scenario is the single most common friction point in the OpenAI Assistants API. It typically occurs not because of an API outage, but due to a misalignment between the API's state machine and the developer's asynchronous logic flow. This guide provides a root cause analysis of the  requires_action  stall and a robust, production-ready implementation in Node.js to resolve it. The Root Cause: The Run Lifecycle and State Locking To fix the stall, you must understand the "lock" mechanism of the Assistants API. The Run object is a state machine. In Progress:  The model is reasoning. Requires Action:  The model determines it needs external data ...