🗓️ Everything *[NYC] is back. A free gathering for AI builders. Sept 9

sanity documents query *[_id in path("/somePath")] currently returning bad pattern

4 repliesLast updated: Nov 29, 2025

Morning, all! Any GROQ folks out there who can tell me what’s wrong with my query? Stumped!
sanity documents query *[_id in path("/somePath")]
currently returning
bad pattern: *[_id
AI Update

The issue with your query is that the command-line is interpreting the parentheses in path("/somePath") as special shell characters. You need to escape or quote your query properly.

Here are a few solutions:

Option 1: Use single quotes around the entire query

sanity documents query '*[_id in path("/somePath")]'

Option 2: Escape the parentheses

sanity documents query "*[_id in path\(\"/somePath\"\)]"

Option 3: Use double quotes and escape inner quotes

sanity documents query "*[_id in path(\"/somePath\")]"

The path() function in GROQ is really useful for filtering documents by their ID path. Here's how it works:

You can also use path() for common patterns like getting all drafts:

*[_id in path("drafts.**")]

The shell escaping issue is a common gotcha when running GROQ queries from the command line - always wrap your queries in quotes to prevent the shell from interpreting special characters! The single quotes option (Option 1) is usually the safest bet since it prevents the shell from interpreting anything inside.

Show original thread
4 replies

Was this answer helpful?

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.

Related contributions