Image field .required() validation not working

8 replies
Last updated: Jan 28, 2026
Has anyone gotten the .required() validation to work on an image type? I didn’t realize until testing it today that no image added is not being flagged…
AI Update

I understand your frustration! This is actually a known issue with how Sanity's validation system works with image fields. The .required() validation on image fields can be tricky because of how image data is structured.

Here's what's happening: When you add .required() to an image field, it only validates that the image field object exists, not that it actually contains an asset reference. An image field in Sanity is an object with properties like asset, crop, and hotspot. So even without an uploaded image, the field can have an empty object {}, which passes the required validation.

The solution is to use custom validation that specifically checks for the asset reference:

defineField({
  name: 'image',
  type: 'image',
  validation: (rule) => rule.custom((value) => {
    if (!value?.asset) {
      return 'Image is required'
    }
    return true
  })
})

Or if you want to keep it more concise with chaining:

defineField({
  name: 'image',
  type: 'image',
  validation: (rule) => rule.required().custom((value) => {
    return value?.asset ? true : 'An image must be uploaded'
  })
})

The key is checking for value?.asset specifically, since that's the actual reference to the uploaded image in your Content Lake.

One important note from the validation documentation: validation only runs client-side in the Studio. If you're using API mutations directly, you'll need to implement server-side validation separately.

This same approach works for file fields too if you run into similar issues there!

Show original thread
8 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?