> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Content Source Maps

Content source maps allow tools to annotate content with metadata and use it to connect tools to content.

The Content Lake can enrich all queries with metadata describing the **source** (the document and attribute) of every content fragment retrieved in the query. This metadata is useful for tooling that runs on the frontend and interprets this information to provide additional ways of interacting with the content for users: for example, displaying content provenance details for compliance reviewers, providing direct links to where to edit the content for editors, and even allowing in-line editing directly in the frontend experience.

This metadata is called Content Source Maps, and it follows the Content Source Maps specification. You can find details about the Content Source Maps specification in the [official specification GitHub repository](https://github.com/sanity-io/content-source-maps).

To request a Content Source Map on a GROQ query, you need to pass the parameter `resultSourceMap=true` when you send your query to the Content Lake HTTP API. When you provide this parameter, the result of your query will include an additional element with the corresponding Content Source Map.

> [!WARNING]
> Requires API version 2021-03-25 or later
> Content Source Maps are supported only in version `2021-03-25` or later of the Content Lake API.

For example, imagine these three documents exist in your dataset:

- A document representing the author George Orwell

```json
{
  "_id": "author-george-orwell-4c9f",
  "_type": "author",
  "died": "1950-01-21",
  "dob": "1903-05-25",
  "firstName": "George",
  "lastName": "Orwell"
}
```

- Another document representing the book “Animal Farm” by author George Orwell (a reference to the document for this author above)

```json
{
  "_id": "book-animal-farm-3856",
  "_type": "book",
  "description": "It tells the story of a group of farm animals who rebel against their human farmer",
  "title": "Animal Farm",
  "author": {
    "_ref": "author-george-orwell-4c9f"
  }
}
```

- And another document representing the book “Nineteen Eighty-Four” by author George Orwell as well (as before, a reference to the first document above)

```json
{
  "_id": "book-1984-12eb",
  "_type": "book",
  "description": "Nineteen Eighty-Four (also published as 1984) is a dystopian social science fiction novel and cautionary tale by English writer George Orwell.",
  "title": "Nineteen Eighty-Four",
  "author": {
    "_ref": "author-george-orwell-4c9f"
  }
}
```

You can run the following GROQ query to obtain a consolidated view that provides the author's last name and a set with the names of the books they have written:

```groq
*[_type == 'author'] {
  "authorName": lastName,
  "booksWritten": *[_type == 'book' && references(^._id)].title
}
```

If you run this query passing the `resultSourceMap` parameter (for example, `https://<project-id>.api.sanity.io/v2026-07-01/data/query/<dataset>?query=<GROQ-query>&resultSourceMap=true`), the response will look like this:

```json
{
  "result": [
    {
      "authorName": "Orwell",
      "booksWritten": ["Nineteen Eighty-Four", "Animal Farm"]
    }
  ],
  "resultSourceMap": {
    "documents": [
      {
        "_id": "author-george-orwell-4c9f",
        "_type": "author"
      },
      {
        "_id": "book-1984-12eb",
        "_type": "book"
      },
      {
        "_id": "book-animal-farm-3856",
        "_type": "book"
      }
    ],
    "paths": ["$['lastName']", "$['title']"],
    "mappings": {
      "$[0]['authorName']": {
        "source": {
          "document": 0,
          "path": 0,
          "type": "documentValue"
        },
        "type": "value"
      },
      "$[0]['booksWritten'][0]": {
        "source": {
          "document": 1,
          "path": 1,
          "type": "documentValue"
        },
        "type": "value"
      },
      "$[0]['booksWritten'][1]": {
        "source": {
          "document": 2,
          "path": 1,
          "type": "documentValue"
        },
        "type": "value"
      }
    }
  }
}

```

Observe that the `resultSourceMap` entry includes:

- Under `documents`, a list of the documents that the content in the query result comes from:- The author document with ID `author-george-orwell-4c9f`,
- The book document with ID `book-1984-12eb`
- The book document with ID `book-animal-farm-3856`


- Under `paths`, a list of the attribute paths that the content in the query result comes from:- The attribute name `lastName` (specified as `"$['lastName']"`)
- The attribute name `title` (specified as `"$['title']"`)


- Under `mappings`, a map where each entry indicates, for each element of the response, what document and path (attribute) from the lists above it comes from. 

For example, this is the first entry in `mappings`:

```json
"$[0]['authorName']": {
    "source": {
      "document": 0,
      "path": 0,
      "type": "documentValue"
    },
    "type": "value"
}
```

This entry says that the value at `$[0]['authorName']` in the result comes from document `0` in `documents` (`author-george-orwell-4c9f`), at path `0` in `paths` (`lastName`). The `document` and `path` values are indexes into those two lists.

The table resolves every entry in `mappings` the same way:

| Response path | Document | Path | Value |
| --- | --- | --- | --- |
| `$[0]['authorName']` | `author-george-orwell-4c9f` (index 0) | `lastName` (index 0) | `"Orwell"` |
| `$[0]['booksWritten'][0]` | `book-1984-12eb` (index 1) | `title` (index 1) | `"Nineteen Eighty-Four"` |
| `$[0]['booksWritten'][1]` | `book-animal-farm-3856` (index 2) | `title` (index 1) | `"Animal Farm"` |

## GROQ compatibility

> [!WARNING]
> Only some GROQ features return source maps
> In the current version of the Content Source Maps capability, only the GROQ features listed below will provide content source metadata in a query. Also note that the feature is currently only supported in the Content Lake (implementations such as groq-js are not yet supported).

Types:

- [Object](https://www.sanity.io/docs/studio/object-type) (includes Portable Text)
- [Array](https://www.sanity.io/docs/studio/array-type)
- [Number](https://www.sanity.io/docs/studio/number-type)
- [String](https://www.sanity.io/docs/studio/string-type)

Traversal:

- Attribute access traversal
- Element access traversal
- Slice traversal
- Filter traversal
- Array postfix traversal
- Projection traversal
- Dereference traversal

Conditionals:

- `select()` (partially supported: result only, for string and number type)
- Conditional projection traversal (partially supported: result only, for string and number type)

Operators:

- Dereference

Functions:

- `string()` (coercing) (partially supported: string(number) only)
- `lower()`
- `upper()`
- `pt::text()`

## GraphQL

Content Source Maps are supported in the Sanity [GraphQL API v2023-08-01](https://www.sanity.io/changelog?platforms=GraphQL#change-9ec89318-a340-4e23-91d9-3154da5b6244) and later. Read more about this in the [GraphQL docs](https://www.sanity.io/docs/content-lake/graphql).



## Related changelog entries

Entries are listed newest first; each link points to the full entry as markdown. Follow one when you need to know what changed, when, or why — for example, to summarize recent updates, explain behavior that differs from older documentation, or check whether a fix has shipped.

- [Sanity Studio v3.10.0: Visual editing, improved integration with Next.js, and more](https://www.sanity.io/docs/changelog/5c520895-3779-4058-b2b9-265973de741f.md) — May 4, 2023