๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Validate schema script

By Espen Hovlandsdal & Rune Botten

A script to validate that your schema is free of errors and warnings


This schema is for an older version of Sanity Studio (v2), which is deprecated.

Learn how to migrate to the new Studio v3 โ†’


// Run this file like this:
// npx sanity exec schema-check.js --mock-browser-env -- --strict
import schema from 'part:@sanity/base/schema'

let hasErrors = false
let hasWarnings = false

for (const item of schema._validation) {
  const path = item.path.map(segment => segment.name).join(' โ†’ ')

  for (const problem of item.problems) {
    if (problem.severity === 'error') {
      hasErrors = true
      console.error(`  - [error] ${problem.message}`)
    } else if (problem.severity === 'warning') {
      hasWarnings = true
      console.warn(`  - [warning] ${problem.message}`)


if (hasErrors) {

if (hasWarnings && process.argv.includes('--strict')) {

This script is useful to run before deploying a Studio, for example as part of a build pipeline, where you can stop a deployment if there are errors or optionally warnings in the schema.

npx sanity exec schema-check.js --mock-browser-env -- --strict && do-your-deploy


Other schemas by authors

Auto-reload Studio when changes are deployed

Drop this into your Studio to let editors know when there's a more recent version of your Studio available, making sure they have the latest fields and validations.

Go to Auto-reload Studio when changes are deployed