PluginBench
Skill
Official
Review
Audit score 70

sanity-best-practices

sanity-io/agent-toolkit

Comprehensive best practices for Sanity schema design, GROQ queries, Visual Editing, and framework integrations.

What is sanity-best-practices?

Official Sanity development best practices covering schema design, GROQ optimization, TypeGen, Visual Editing, Portable Text, Sanity Functions, Blueprints, and integrations with Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, and Hydrogen. Use this when building or reviewing Sanity projects, designing content models, or implementing frontend integrations.

  • Schema design and field definition patterns with validation and deprecation guidance
  • GROQ query optimization, type safety, and performance best practices
  • Visual Editing and Presentation Tool setup with live preview and Stega overlays
  • Framework integration guides for Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, and Hydrogen
  • Sanity Functions and Blueprints for content automation and infrastructure as code
  • Studio structure configuration, localization patterns, and content migration strategies

How to install sanity-best-practices

npx skills add https://github.com/sanity-io/agent-toolkit --skill sanity-best-practices
Prerequisites
  • Sanity project initialized and CLI installed
  • Basic familiarity with Sanity Studio and content modeling
Claude Code
Cursor
Windsurf
Cline

How to use sanity-best-practices

  1. 1.Identify the relevant topic or framework guide from the Quick Reference section
  2. 2.Read the corresponding reference file for detailed explanations and code examples
  3. 3.Apply the patterns and best practices to your schema, queries, or integration
  4. 4.Reference the Global Rules for document ID generation and relationship modeling
  5. 5.Consult additional guides only when your task crosses multiple concerns

Use cases

Good for
  • Setting up a new Sanity project with proper schema and Studio structure
  • Integrating Sanity with a Next.js or other frontend framework for live content editing
  • Optimizing GROQ queries for performance and type safety in production
  • Implementing Visual Editing with the Presentation Tool and live preview
  • Automating content workflows with Sanity Functions and event handlers
Who it's for
  • Sanity developers building new projects or maintaining existing codebases
  • Frontend engineers integrating Sanity with Next.js, Nuxt, Astro, or other frameworks
  • Content architects designing schemas and content models
  • DevOps engineers managing Sanity infrastructure with Blueprints
  • Teams implementing content automation with Sanity Functions

sanity-best-practices FAQ

When should I use explicit document IDs vs. letting Sanity generate them?

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.

How should I model relationships between documents?

Use reference fields to model relationships, then resolve related documents with GROQ lookups, source-key fields, or returned _id values from created documents.

Which framework guide should I start with?

Start with the single framework or topic guide that best matches your request (e.g., nextjs, nuxt, astro). Read additional references only when your task crosses multiple concerns.

What topics does this skill cover?

Schema design, GROQ queries, TypeGen, Visual Editing, images, Portable Text, Studio structure, localization, migrations, Sanity Functions, Blueprints, and integrations with Next.js, Nuxt, Astro, Remix, SvelteKit, Angular, and Hydrogen.

Can this skill help with content migration?

Yes. The skill includes migration guides covering content import overview and HTML to Portable Text conversion with @portabletext/block-tools.

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, 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, Sanity Functions, 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

Global Rules

  • Let Sanity generate _id values for ordinary documents. Do not create deterministic UUIDs, slug-derived IDs, or legacy-system IDs when creating documents.
  • Model relationships with reference fields, then resolve related documents with GROQ lookups, source-key fields, or returned _id values from created documents.
  • Use explicit document IDs mainly for singleton documents controlled by Studio Structure, including localized singletons such as homePage-en.

Quick Reference

Integration Guides

  • get-started - Interactive onboarding for new Sanity projects
  • nextjs - Next.js App Router, Live Content API, standalone Studio
  • nuxt - Nuxt integration with @nuxtjs/sanity
  • angular - Angular integration with @sanity/client, signals, resource API
  • astro - Astro integration with @sanity/astro
  • remix - React Router / Remix integration
  • svelte - SvelteKit integration with @sanity/svelte-loader
  • hydrogen - Shopify Hydrogen with Sanity
  • project-structure - Standalone Studio and monorepo patterns
  • app-sdk - Custom applications with Sanity App SDK
  • blueprints - Infrastructure as Code with Sanity Blueprints
  • functions - Automating content workflows with Sanity Functions

Topic Guides

  • groq - GROQ query patterns, type safety, performance optimization
  • schema - Schema design, field definitions, validation, deprecation patterns
  • visual-editing - Presentation Tool, Stega, overlays, live preview
  • page-builder - Page Builder arrays, block components, live editing
  • portable-text - Rich text rendering and custom components
  • image - Image schema, URL builder, hotspots, LQIP, Next.js Image
  • studio-structure - Desk structure, singletons, navigation
  • typegen - TypeGen configuration, workflow, type utilities
  • seo - Metadata, sitemaps, Open Graph, JSON-LD
  • localization - i18n patterns, document vs field-level, locale management
  • migration - Content import overview (see also migration-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.

SE

seo-aeo-best-practices

Official
sanity-io/agent-toolkit

SEO and AEO best practices for metadata, Open Graph, sitemaps, robots.txt, hreflang, JSON-LD structured data, EEAT, and content optimized for search engines and AI answer surfaces. Use this skill when implementing page SEO, technical SEO, schema markup, international SEO, AI-overview readiness, or improving content for Google, ChatGPT, Perplexity, and similar assistants.

4.1k installsAudited
SA

sanity-migration

sanity-io/agent-toolkit

Plans, implements, and reviews migrations from other CMSes and content systems into Sanity. Use when migrating or replatforming to Sanity from AEM, Adobe Experience Manager, Contentful, Strapi, Webflow, WordPress, Payload, Drupal, Markdown/MDX/frontmatter files, WXR/XML exports, CMS APIs, database dumps, static HTML, or when designing extraction, transformation, Portable Text conversion, asset migration, redirects, validation, and cutover workflows.

3.9k installsAudited
CO

content-modeling-best-practices

Official
sanity-io/agent-toolkit

Structured content modeling guidance for schema design, content architecture, content reuse, references versus embedded objects, separation of concerns, and taxonomies across Sanity and other headless CMSes. Use this skill when designing or refactoring content types, deciding field shapes, debating reusable versus nested content, planning omnichannel content models, or reviewing whether a schema is too page-shaped or presentation-driven.

2.8k installsAudited
CO

content-experimentation-best-practices

Official
sanity-io/agent-toolkit

Content experimentation and A/B testing guidance covering experiment design, hypotheses, metrics, sample size, statistical foundations, CMS-managed variants, and common analysis pitfalls. Use this skill when planning experiments, setting up variants, choosing success metrics, interpreting statistical results, or building experimentation workflows in a CMS or frontend stack.

2.2k installsAudited
PO

portable-text-serialization

Official
sanity-io/agent-toolkit

Render and serialize Portable Text to React, Svelte, Vue, Astro, HTML, Markdown, and plain text. Use when implementing Portable Text rendering in any frontend framework, building custom serializers for non-standard block types, converting Portable Text to HTML strings server-side, converting Portable Text to Markdown, extracting plain text from Portable Text, or troubleshooting rendering issues with marks, blocks, lists, or custom types.

1.1k installsAudited
PO

portable-text-conversion

Official
sanity-io/agent-toolkit

Convert HTML and Markdown content into Portable Text blocks for Sanity. Use when migrating content from legacy CMSs, importing HTML or Markdown into Sanity, building content pipelines that ingest external content, converting rich text between formats, or programmatically creating Portable Text documents. Covers @portabletext/markdown (markdownToPortableText), @portabletext/block-tools (htmlToBlocks), custom deserializers, and the Portable Text specification for manual block construction.

1.1k installs