
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYes, you can populate a schema with read-only data in Sanity! There are several approaches depending on your use case:
readOnly PropertyThe simplest way is to use the readOnly property on your field definitions. This makes fields visible but not editable:
{
name: 'generatedId',
type: 'string',
readOnly: true
}You can also make fields read-only based on conditions using callback functions, as explained in the Conditional Fields documentation:
{
name: 'publishedDate',
type: 'datetime',
readOnly: ({document}) => document?.status === 'published'
}The callback receives parameters like parent, document, value, and currentUser, allowing you to create dynamic read-only logic.
To actually populate these read-only fields with data, you have a few options:
{
name: 'createdAt',
type: 'datetime',
readOnly: true,
initialValue: () => new Date().toISOString()
}Document actions - Use custom document actions to programmatically set values before saving
Mutations via API - Populate data through the Sanity API (mutations can write to read-only fields - the read-only restriction only applies to the Studio UI)
Sanity Functions - Use Sanity Functions to automatically populate fields when documents are created or updated through event handlers
The key thing to remember is that readOnly only affects the Studio editing interface - it doesn't prevent programmatic updates via the API. This gives you flexibility to populate data through automated processes while preventing manual editing by content creators.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store