sanity-best-practices
sanity-io/agent-toolkit
Sanity development best practices for schema design, GROQ, TypeGen, Visual Editing, and framework integrations.
What is sanity-best-practices?
Comprehensive reference for Sanity CMS development covering schema design, GROQ queries, content modeling, and integrations with Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, and Hydrogen. Use this skill when building or reviewing Sanity projects, designing schemas, writing queries, setting up Visual Editing, or integrating with frontend frameworks.
- Provides schema design patterns and field definition best practices
- Covers GROQ query optimization and type-safe query patterns
- Guides Visual Editing and live preview setup with Stega overlays
- Explains image handling, hotspots, LQIP, and Next.js Image integration
- Documents Portable Text rendering and custom component patterns
- Covers Sanity Functions, webhooks, and event-driven content automation
How to install sanity-best-practices
npx skills add https://github.com/sanity-io/agent-toolkit --skill sanity-best-practicesHow to use sanity-best-practices
- 1.Identify the relevant topic or framework guide matching your task (e.g., nextjs, groq, schema, visual-editing)
- 2.Read the corresponding reference file for detailed explanations and code examples
- 3.Review incorrect vs. correct code patterns and decision matrices provided
- 4.Apply the patterns to your Sanity project or codebase
- 5.Reference global rules for document IDs, relationships, and video handling
Use cases
- Setting up a new Sanity project with schema design and Studio structure
- Integrating Sanity with a Next.js or Nuxt frontend using Live Content API
- Optimizing GROQ queries for performance and type safety
- Implementing Visual Editing with live preview in a frontend application
- Migrating content from other systems using HTML-to-Portable Text conversion
- Sanity developers building new projects
- Frontend engineers integrating Sanity with React, Vue, Svelte, or Angular frameworks
- Content architects designing schemas and content models
- DevOps engineers setting up Sanity infrastructure with Blueprints
- Full-stack developers implementing Visual Editing and live preview
sanity-best-practices FAQ
Let Sanity generate _id values for ordinary documents. Use explicit IDs mainly for singleton documents controlled by Studio Structure, including localized singletons like homePage-en.
Do not store production video in file assets—they lack transcoding and adaptive streaming. Use Sanity Media Library with Mux on Enterprise plans, or integrate a dedicated service like YouTube, Vimeo, or sanity-plugin-mux-input on other plans.
Use reference fields to model relationships, then resolve related documents with GROQ lookups, source-key fields, or returned _id values from created documents.
Choose the guide matching your frontend framework: nextjs, nuxt, astro, remix, svelte, angular, or hydrogen. Start with that single guide, then reference additional topics only when crossing concerns.
TypeGen generates TypeScript types from your Sanity schema for type-safe queries and content modeling. Configure it in your project to ensure type safety across GROQ queries and schema definitions.
Full instructions (SKILL.md)
Source of truth, from sanity-io/agent-toolkit.
name: sanity-best-practices description: Sanity development best practices for schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, webhooks, Blueprints, and framework integrations such as Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, Hydrogen, and the App SDK. Use this skill whenever working with Sanity schemas, defineType or defineField, GROQ or defineQuery, content modeling, Presentation or preview setups, Sanity-powered frontend integrations, event-driven content automation, documentEventHandler, defineDocumentFunction, defineMediaLibraryAssetFunction, @sanity/functions, @sanity/blueprints, sanity.blueprint.ts, event-driven content automation, or when reviewing and fixing a Sanity codebase.
Sanity Best Practices
Comprehensive best practices and integration guides for Sanity development, maintained by Sanity. Use the quick reference below to load only the one or two topic files that match the task.
When to Apply
Reference these guidelines when:
- Setting up a new Sanity project or onboarding
- Integrating Sanity with a frontend framework (Next.js, Nuxt, Astro, Remix, SvelteKit, Hydrogen)
- Writing GROQ queries or optimizing performance
- Designing content schemas
- Implementing Visual Editing and live preview
- Working with images, Portable Text, or page builders
- Configuring Sanity Studio structure
- Setting up TypeGen for type safety
- Implementing localization
- Migrating content from other systems
- Building custom apps with the Sanity App SDK
- Managing infrastructure with Blueprints
- Automating content workflows with Sanity Functions or webhooks
Global Rules
- Let Sanity generate
_idvalues for ordinary documents. Do not create deterministic UUIDs, slug-derived IDs, or legacy-system IDs when creating documents. - Model relationships with
referencefields, then resolve related documents with GROQ lookups, source-key fields, or returned_idvalues from created documents. - Use explicit document IDs mainly for singleton documents controlled by Studio Structure, including localized singletons such as
homePage-en.
Video
- Do not store or serve video from Sanity
fileassets for production playback. File assets are delivered as raw downloads with no transcoding or adaptive streaming, and video traffic drives very high bandwidth usage and unexpectedly large bills. - On Enterprise plans with the video add-on, use Sanity Media Library for video: uploads are transcoded and streamed adaptively via Mux. Model video fields with
defineVideoField()fromsanity/media-libraryand play them with@mux/mux-player-reactusing the asset's playback ID. - On other plans, use a dedicated video service: install
sanity-plugin-mux-inputto upload and manage videos in your Mux account from the Studio, or host video on a platform such as YouTube or Vimeo and store only the embed URL in Sanity. - Small clips and short previews in a
filefield are acceptable, but any user-facing video at scale must go through Media Library or a streaming service.
Quick Reference
Integration Guides
get-started- Interactive onboarding for new Sanity projectsnextjs- Next.js App Router, Live Content API, standalone Studionuxt- Nuxt integration with @nuxtjs/sanityangular- Angular integration with @sanity/client, signals, resource APIastro- Astro integration with @sanity/astroremix- React Router / Remix integrationsvelte- SvelteKit integration with @sanity/svelte-loaderhydrogen- Shopify Hydrogen with Sanityproject-structure- Standalone Studio and monorepo patternsapp-sdk- Custom applications with Sanity App SDKblueprints- Infrastructure as Code: blueprint files, stacks, plan/deploy workflow, error recovery, CI deploysfunctions- Automating content workflows with Sanity Functions and webhooks
Topic Guides
groq- GROQ query patterns, type safety, performance optimizationschema- Schema design, field definitions, validation, deprecation patternsvisual-editing- Presentation Tool, Stega, overlays, live previewpage-builder- Page Builder arrays, block components, live editingportable-text- Rich text rendering and custom componentsimage- Image schema, URL builder, hotspots, LQIP, Next.js Imagestudio-structure- Desk structure, singletons, navigationtypegen- TypeGen configuration, workflow, type utilitiesseo- Metadata, sitemaps, Open Graph, JSON-LDlocalization- i18n patterns, document vs field-level, locale managementmigration- Content import overview (see alsomigration-html-import)migration-html-import- HTML to Portable Text with @portabletext/block-tools
How to Use
Start with the single framework or topic guide that best matches the request, then read additional references only when the task crosses concerns. Use these reference files for detailed explanations and code examples:
references/groq.md
references/schema.md
references/nextjs.md
Each reference file contains:
- Comprehensive topic or integration coverage
- Incorrect and correct code examples
- Decision matrices and workflow guidance
- Framework-specific patterns where applicable
Related skills
More from sanity-io/agent-toolkit and the wider catalog.

sanity-migration
Plan, implement, and validate CMS-to-Sanity migrations with structured ETL workflows.

seo-aeo-best-practices
SEO and AEO best practices for metadata, structured data, sitemaps, and AI answer engine optimization.

content-experimentation-best-practices
A/B testing and experimentation guidance for content-driven products and CMS workflows.

content-modeling-best-practices
Structured content modeling guidance for schema design, reusability, and multi-channel delivery in headless CMSes.

book-study
Systematic reading coach with knowledge compilation, mastery testing, and spaced repetition for deep book learning.

code-review-expert
Expert code review of git changes detecting SOLID violations, security risks, and proposing actionable improvements.