In the chaotic world of content management, 'fact drift' is the silent killer of trust. When a product manager updates a refund policy from 30 to 60 days in one CMS field, the rest of the site often stays stubbornly outdated. Developer Pritam Patra has built Fact Ledger, a Sanity Content Lake submission that tackles this structural flaw by treating business values as first-class documents rather than dead text. The system ensures that when a canonical fact changes, every referencing page updates automatically, or flags the discrepancy for immediate remediation.
The Architecture: Rules Flag, AI Drafts, Human Approves
The core philosophy of Fact Ledger is distilled into a four-step loop: 'Rules flag. AI drafts. Human approves. Sanity remembers.' The detection layer is entirely deterministic, relying on pure TypeScript scanner rules (R1βR5) that run in milliseconds without any AI involvement. These rules catch unlinked matches, contradictions, deprecated references, orphan facts, and temporal violations. For example, Rule 2 (Contradiction) uses a proximity window to only flag numbers near a fact's label, avoiding false positives from phone numbers or copyright years. This precision resulted in 100% recall and 0 false positives against a benchmark of 31 planted violations.
AI Agents as Remediation Architects, Not Publishers
Once the deterministic scanner identifies drift, an AI agent enters the chatβbut not as the final decision-maker. The agent fetches the page's Portable Text, locates the exact stale spans, and synthesizes valid Sanity patch mutations. Crucially, the AI never publishes anything autonomously. It drafts a 'remediation document' containing before/after diffs and raw patch JSON. A human editor reviews these changes in Sanity Studio and clicks 'Apply Fixes & Publish.' This triggers an atomic client.transaction() that patches every affected page, flips findings to fixed, and writes an immutable audit ledger entry. If the tab closes mid-process, the transaction ensures no partial states exist.
Building with Antigravity IDE and Vibe-Coding Constraints
Patra built the system over 7.5 hours using Antigravity IDE (Google DeepMind), leveraging 'vibe-coding' techniques to rapidly prototype the schema and scanner. The development process revealed interesting insights about AI capabilities: the model correctly inferred the need for atomic transactions without explicit prompting, understanding that sequential patches could leave a dataset in a half-consistent state. However, it also hit practical walls, such as attempting to use Sanity Functions for webhooks, which required a paid plan upgrade. The fallback to a Next.js API route proved more deployable, illustrating the gap between elegant code and shippable infrastructure.
Key Takeaways
- Deterministic scanning outperforms AI detection for exact value matching, achieving 100% precision on benchmark tests.
- AI agents are most effective when constrained to drafting mutations, leaving final approval and publishing to human editors.
- Atomic transactions in Sanity prevent partial updates, ensuring data consistency even if remediation processes fail mid-stream.
- 'Vibe-coding' can rapidly prototype complex architectures, but real-world constraints like pricing tiers still dictate final implementation choices.
The Bottom Line
Fact Ledger proves that the future of AI in content management isn't about autonomous publishing, but about augmenting human judgment with deterministic rigor. By keeping the AI strictly in the drafting role and using pure code for detection, Patra has created a workflow that is both scalable and trustworthy.