Stop Burning Hidden Reasoning Tokens on Deterministic Math: Putting a Local AST Pre-Solver in Front of LLMs A developer building Omnivas Core described an architecture that routes deterministic math problems through a local AST pre-solver before any LLM call, so expressions like quadratics and arithmetic are solved and verified on-device at zero token cost. A conservative intent guard skips interception for multi-part, code-generation, or long prompts, forwarding those to models such as Claude, GPT, Gemini, DeepSeek, or Ollama, with an optional deterministic gate for verifying reasoning outputs. The developer says the approach avoids the 1,500–3,000 hidden reasoning tokens models typically spend on simple problems and is testable as a guest on omnivas.ai. If you've built anything on top of modern reasoning models Claude, GPT, Gemini, DeepSeek , you've probably noticed an expensive pattern: Ask a reasoning model to solve a straightforward quadratic like 2x^2 + 5x - 3 = 0 or evaluate 17 24 + 89 89 , and it will happily burn 1,500–3,000 hidden thinking tokens before returning an answer that a 50-line parser could compute deterministically. Even worse, the usual fix—LLM tool-calling having the model call Python or SymPy —still pays for a full LLM round-trip and hidden reasoning tokens before and after the tool call. The Architecture Shift: Pre-Solve Before the LLM While building Omnivas Core, I flipped the pipeline around so deterministic expressions never reach an LLM in the first place: text User Prompt │ ▼ Stage 1: Local / Edge AST Pass-Through ├── Deterministic match arithmetic, quadratics, derivatives, integrals │ └── Solve + verify locally → 0 LLM tokens billed │ └── Open-ended / word problem / code └── Forward to LLM Gemini, Claude, GPT, DeepSeek, Ollama └── Optional Stage 2: Closed-World Deterministic Gate Keeping the Router Conservative The biggest trap with pre-LLM interception is being too aggressive and accidentally hijacking a complex multi-part prompt. In practice, adding a strict intent guard before matching keeps false positives at zero: js export function evaluateAstPassThrough prompt = '' { const clean = prompt.trim .toLowerCase .replace / ?. +$/, '' .trim ; const wordCount = clean.split /\s+/ .filter Boolean .length; // Never intercept multi-part, document, or code-generation prompts if wordCount 22 || prompt.includes '\n' || /\b write|build|create|debug|refactor|explain why|essay|code \b/i.test clean { return { matched: false }; } // Example: Quadratic equation AST match e.g. "Solve 2x^2 + 5x - 3 = 0" const quad = clean.match /^ ?:solve\s+ ? +- ?\d \s x^2\s +- \s \d \s x\s +- \s \d+ \s =\s 0$/i ; if quad return { matched: false }; const a = parseCoeff quad 1 ; const b = parseCoeff quad 2 ; const c = parseFloat quad 3 .replace /\s+/g, '' ; const disc = b b - 4 a c; if a === 0 || disc < 0 return { matched: false }; const x1 = -b + Math.sqrt disc / 2 a ; const x2 = -b - Math.sqrt disc / 2 a ; return { matched: true, discriminant: disc, roots: x1, x2 }; } Anything that doesn't cleanly match falls straight through to the LLM—and if strict verification is needed on word problems or reasoning outputs, a toggleable Deterministic Gate enforces closed-world checks around the model response. Try It Live No Login Required You can test the local AST pass-through and Deterministic Gate directly at omnivas.ai no signup needed for guest prompts—clicking the Solve 2x² + 5x - 3 = 0 chip executes locally with 0 LLM API calls . I'd love to hear from other devs building AI apps: what other deterministic classes regex validation, cron parsing, unit conversions, SQL linting? would you intercept before touching an LLM?