Sanity

Master headless CMS development with Sanity, including content modeling best practices, GROQ query optimization, Studio customization, real-world implementation patterns, and building scalable content platforms.

Ai genreated image wat workflow
AISanity

Using the WAT Framework: Writing Sanity MCP Workflows That Make Claude Consistent and Reliable

The text explains why open-ended AI instructions like “write a blog post about TypeScript” lead to inconsistent results. Because models are probabilistic, they vary structure, miss fields, and overlook edge cases, which is problematic for repetitive, structured tasks such as publishing to a CMS. To solve this, it introduces the WAT framework: Workflows, Agents, Tools. Workflows are plain-language markdown SOPs that encode domain knowledge and specify steps. Agents (Claude) handle reasoning and decisions. Tools are deterministic scripts or APIs, like the Sanity MCP, that execute actions. This separation narrows the decision space and keeps behavior consistent across sessions. A concrete example is the draft_blog_post workflow, which fetches authors and categories from Sanity, requires outline approval, and strictly defines document shape and constraints, including a 5000-byte body limit. Workflows evolve through a self-improvement loop: each failure adds new rules and edge cases. To get started, you document repeatable tasks, inputs, tools, steps, and edge cases, store them in .claude/wat/workflows/, and reuse them for faster, cheaper, and more reliable AI-assisted work.

15.03.2026
2 min read
ai agent
AINextJSSanity

Serving Your Blog as Markdown So AI Agents Can Actually Read It

The article explains how to serve clean Markdown versions of blog posts so AI agents can consume content without HTML noise like navigation, scripts, and cookie banners. It recommends two access patterns: appending .md to post URLs, or using an Accept: text/markdown header for content negotiation. In Next.js, rewrites in next.config.ts route both patterns to an internal /md/posts/[slug] handler. That route fetches the post from Sanity, converts it to Markdown, and returns it with a text/markdown Content-Type and short caching headers. A buildPostMarkdown helper constructs the Markdown document with a title, canonical URL, optional hero image, auto-generated summary, and body converted from Portable Text via @portabletext/markdown. Code blocks stored in Sanity as _type: "code" are correctly rendered as fenced Markdown code blocks with language tags, making them ideal for AI agents and syntax highlighters. A /posts.md index provides a machine-readable sitemap listing all posts with metadata and links, enabling agents to discover and traverse content efficiently using either the .md suffix or Accept header approach.

15.03.2026
2 min read
Ai written in tiles covered in sand
AISanity

Content Agent: AI That Runs Content Operations at Scale

Content Agent is an AI built specifically for large-scale content operations, going far beyond traditional AI writing assistants that only handle one document at a time. It understands your content schema—including document types, fields, validation rules, and relationships—so it can transform raw source material into structured content, audit entire libraries, and execute coordinated updates across thousands of documents. Key capabilities include pipeline transformations from sources like press releases or specs into blog posts or product pages, large-scale analysis to detect missing metadata or outdated content, intelligent bulk editing for rebrands and URL changes, visual editing of images via natural language, and integrated web research to keep content accurate and current. Technically, it leverages document sets, staged changes with reviewable releases, schema-aware validation, a specialized multi-agent architecture, and direct integration with Sanity’s Content Lake. Content Agent is included in all Sanity plans and uses an AI credit system based on queries and actions, with clear examples of typical usage and tools for monitoring and controlling costs.

17.01.2026
7 min read
Cookies used as a metaphore
NextJSSanity

Building a GDPR-Compliant Cookie Consent System with Sanity CMS

The author decided to build a custom cookie consent solution for their blog to avoid the complexities and privacy issues of third-party libraries. Their solution is fully GDPR-compliant, privacy-first, and integrates with Sanity CMS. The custom implementation includes three main components: a Sanity CMS schema for managing consent content, a React Context for state management, and conditional loading of analytics based on user consent. The system emphasizes accessibility, server-side data fetching, and smart reload logic to ensure a seamless user experience. The cookie banner is designed to be editor-friendly, allowing non-technical users to update content without code changes. The result is a lightweight, under 5KB, GDPR-compliant system that respects user privacy by default, loads no third-party tracking libraries, and provides full transparency with a detailed policy page. Users can withdraw consent at any time, and the system is fully accessible, making it an ideal solution for personal blogs or small sites.

30.12.2025
3 min read
studio microphone
AISanity

Automating Audio Narration with Sanity Blueprints and Google Text-to-Speech

I recently developed an automated audio narration pipeline for my blog using Sanity, Next.js, and Google Cloud Text-to-Speech. The system regenerates a high-quality MP3 narration automatically whenever the blog post content changes, avoiding manual steps, wasted API calls, or infinite loops. The process relies on Sanity's native automation tools, including Blueprints, delta detection, and GROQ projections. The system reacts to content changes at the CMS level, triggering narration generation only when the blog post's body field changes. This is achieved by using Sanity's delta function to detect changes and a secure webhook to initiate the narration generation via a Next.js API route. The generated MP3 is uploaded back to Sanity and linked to the post. This ensures narration is generated only once per meaningful content change. Storing the audio in Sanity is effective for a personal blog, as it utilizes Sanity's CDN, keeps editorial state and content in one place, and eliminates the need for extra storage services. The result is a fully automated, content-driven audio system with no manual triggers, unnecessary TTS calls, or client-side secrets, providing a clean separation of concerns and scalability.

25.12.2025
2 min read
brain illustration
AISanity

Building Event-Driven Content Automation: Auto-Summaries with Sanity Agent

This post discusses the implementation of an automatic summary generation system using Sanity's event-driven architecture. The system leverages Sanity Agent, Sanity Functions, and Blueprints to autonomously generate summaries when content is published. It consists of three main components: a Sanity Blueprint that triggers on post publication, a Sanity Function that orchestrates summary generation, and a Sanity Agent that processes content through a language model to create summaries. The event-driven architecture allows the system to react immediately to content changes, eliminating manual intervention and scaling efficiently with content volume. This approach ensures consistent and timely summary generation, enhancing content workflows. The architecture can be extended to other automated tasks like image optimization and SEO metadata generation, treating content as an active event source rather than passive data.

22.12.2025
6 min read
robot
AISanity

The AI-Driven Journey: Crafting Content with Sanity MCP

Sanity MCP is a Model Context Protocol server that connects AI assistants directly to the Sanity CMS, enabling schema-aware content creation, editing, and querying through natural language. Hosted at mcp.sanity.io and available via simple OAuth, it ships with 34 tools for document operations, schema management, image generation, semantic search, and GROQ queries, and is supported by popular AI clients like Claude Code, Cursor, VS Code with Copilot, and more. This post itself was written entirely by an AI assistant through Sanity MCP, illustrating a workflow of Human Strategy → AI Execution → Human Review → AI-assisted bulk edits → Human Approval. Real-world applications include the Sanity Content Agent for large-scale audits and transformations, Agent Actions and Sanity Functions for automated workflows, and marketing use cases like SEO landing pages, translation, and content gap analysis. The article emphasizes ethical transparency about AI-generated content and positions MCP as part of an emerging industry standard for agentic AI, where human creators are augmented—not replaced—by AI-driven, conversational content management.

17.03.2026
4 min read
Reading time
Sanity

Reading time sanity blog

Reading time estimates are useful for readers to gauge their engagement time with content. For Sanity-powered blogs, calculating reading time is challenging due to Sanity's block content storing rich text as structured data. The recommended solution is to calculate reading time directly in a GROQ query. This involves using the pt::text() function to extract plain text from Portable Text blocks, splitting the text to count words, and dividing by 200 to estimate minutes to read, based on an average reading speed of 200 words per minute. Calculating reading time in GROQ queries enhances performance by reducing client-side processing and improving load times. Adjust the average reading speed based on the complexity of your content for more accurate estimates.

22.12.2025
1 min read