Diagnosing Empty GROQ Query Results in Sanity Studio
Learn why a GROQ query may return [] or null even when matching documents exist, and follow ordered checks to isolate syntax, schema, locale, or permission issues.
05 Sept 2026, 16:05 UTC

Recognizable condition
You run a GROQ query in Sanity Vision, your custom frontend, or a CLI script and receive an empty array ([]) or null even though you know documents that should match the filter exist in the dataset.
Cause / diagnostic table
| Possible cause | What to look for |
|---|---|
| Syntax error (missing parentheses, wrong attribute path) | Query fails silently and returns no rows; Vision may show a warning icon. |
| Schema type name mismatch | The _type value in the query does not exactly match the schema definition (case‑sensitive). |
| Language/locale filtering | Dataset uses a language field (e.g., _lang) and the query omits the locale condition, causing the default locale to return none. |
| Insufficient token permissions | The request uses a token that lacks read scope for the dataset or specific document IDs. |
| Recent schema change not yet loaded | After adding/removing fields, the Studio or CDN may still serve an outdated schema version. |
Ordered verification checks
- Inspect the query syntax
Open Sanity Vision (
https://<project-id>.sanity.studio/vision) and paste the query. Look for any red underline or warning tooltip. Fix obvious typos such as missing parentheses or incorrect field names (e.g.,slug.currentvsslug).*[_type == "article" && slug.current == "my-post"] - Confirm schema type name
In the Studio, go to
Schema Typesand locate the type you are querying (e.g.,article). Ensure the spelling and casing match exactly what you used in_type. If the type is defined asArticlewith a capital A, the query must useArticle. - Check for language/locale filters
If your dataset includes a language field (commonly
_langor a customlanguagestring), the query must either:- Include an explicit locale condition:
*[_type == "article" && (_lang == "en" || !defined(_lang))] - Or remove the locale restriction if you want all languages.
Test both versions in Vision to see if results appear.
- Include an explicit locale condition:
- Validate token permissions
Determine which token your application or CLI uses. Run:
sanity auth listLook for the token’s scopes; it must contain
read. If you are using a custom token, verify it in the project settings underAPI → Tokens. As a quick test, replace the token with a knownread-enabled token (e.g., the developer token) and re‑run the query. - Force schema/CDN refresh
If you recently edited the schema, restart the local Studio:
sanity startOr, in the Sanity dashboard, navigate to
Settings → API → CDNand clickPurge cache. Then re‑run the query in Vision.
Fixes tied to findings
- Syntax: Correct the query and save it in your codebase.
- Schema mismatch: Align the query’s
_typevalue with the schema definition (or rename the schema type if appropriate). - Locale: Add the needed locale condition or adjust your dataset’s language strategy.
- Token: Generate a new token with
readscope or update the existing token’s permissions. - Schema cache: Restart Studio or purge CDN cache to load the latest schema.
Escalation criteria
If after completing all five checks the query still returns empty results:
- Verify that the documents are actually
published(not only drafts) by toggling the?includeDrafts=trueparameter in Vision. - Check the dataset’s
_idvalues directly via theDocumentslist to ensure the expected IDs exist. - Contact Sanity support with the exact query, token scopes (redacted), and a screenshot of Vision showing the empty result, noting the dataset name and project ID.
These steps help distinguish between a genuine data absence and a configuration or permission issue, allowing you to resolve the problem or provide the support team with the necessary diagnostics.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.