Skip to content
Ritesh FirodiyaGet in touch

Work / Chitragupt / Wiki / Decisions

2026-05-31-hybrid-parsing-haiku-fallback

Decisioncanonicalverified 2026-06-26

DECISION.2026-05-31.HYBRID-PARSING-HAIKU-FALLBACK

Hybrid parsing: regex-first, Haiku 4.5 fallback on unknown / low-confidence / scanned

Decision

Parse with regex first; fall back to Claude Haiku 4.5 only on classification confidence < 0.7, form_type === "unknown", scanned PDFs with text-recovery < 50 chars/page, or zod-schema-invalid regex output. OCR uses Haiku vision. No Sonnet escalation in V1.

Why

28 deterministic parsers cover stable government forms (Form 16 / 26AS / AIS / TIS / ITR-V / CAMS CAS / NPS CRA). They fail on the long tail (multi-bank statements, multi-broker reports, custom invoices, scanned + password-locked PDFs). LLM-only would cost more and reduce explainability on tax-grade fields. Hybrid keeps regex free for the stable case and pays per-call only when regex can't help.

Impact

  • New module apps/functions/src/parser/llm-fallback.ts using @anthropic-ai/sdk with claude-haiku-4-5.
  • Triggered when classification confidence < 0.7, form_type === "unknown", scanned with text-recovery < 50 chars/page, or zod-schema-invalid regex output.
  • Prompt-cached system prompt + tool schema (~3K tokens) to keep average cost at ~$0.008–$0.012/doc.
  • No Sonnet escalation in V1 — hard layouts land as needs_classification for manual override.
  • OCR for scanned PDFs uses Haiku vision (single SDK discipline) — no Mistral OCR / Textract added.
  • Affects inbox-document-types, pillar-inbox, infra-sub-processors (Anthropic SDK is the only LLM dependency).

Status

Active.

Sources

  • .context/wiki/decisions/* § "2026-05-31 — Hybrid parsing: regex-first, Haiku 4.5 fallback on unknown / low-confidence / scanned"

Every project of mine is written down like this.

Read the résumé