---
title: "Auditing document compliance: Studio"
description: "Audit existing RavenDB documents for JSON Schema compliance through the Studio UI to review and fix non-conforming documents."
url: "https://docs.ravendb.net/7.2/documents/schema-validation/auditing-document-compliance/auditing-document-compliance_studio"
version: "7.2"
---

# Auditing document compliance: Studio

> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

## Auditing document compliance: Studio

> **Note**
>
> To check document compliance with a validation schema via Studio, you can:
>
> - Run a manual [validation test operation](#running-a-validation-test), that goes through a collection or a part of it and reports invalid documents and their validation errors.
> - Create an [audit index](#audit-documents-compliance-by-index), that validates documents during indexing and stores any validation error messages in the index, so the documents can be queried by compliance status and specific validation error messages.
>
> * In this article:
>   - [Running a validation test](#running-a-validation-test)
>     - [Test a schema using the Document Schema view](#test-a-schema-using-the-document-schema-view)
>     - [Test a schema using the Schema Playground](#test-a-schema-using-the-schema-playground)
>   - [Audit documents compliance by index](#audit-documents-compliance-by-index)
>     - [Define a validation schema](#define-a-validation-schema)
>     - [Create the audit index](#create-the-audit-index)
>     - [Query the index](#query-the-index)

## Running a validation test {#running-a-validation-test}

You can initiate a compliance test operation that validates documents against a schema, using either a defined schema listed in the [Document Schema view](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#managing-and-testing-existing-schemas) or the [Schema playground](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#the-schema-playground) views.

### Test a schema using the Document Schema view

The validation schemas that you already defined are displayed in the [Document Schema view](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#creating-a-collection-schema), where you can test each schema against documents in the associated collection.

![Test collection schema](https://docs.ravendb.net/assets/images/schema-validation_studio_audit-test-3e2d1841b744abd6b2e625c3faae079b.png)

- Use this method to verify schema effectiveness and documents compliance with schema constraints.
- Test results include the number and names of invalid documents, and the validation error messages generated for each document.
- You can validate an entire collection or a specified number of documents. This is helpful when working with large collections.
- Find [here](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#managing-and-testing-existing-schemas) a detailed explanation of this view.

### Test a schema using the Schema Playground

The [Document Schema](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#creating-a-collection-schema) view also provides an isolated playground environment for experimentation, allowing you to define schemas and try them out on your data without affecting your existing collections or schemas.

![Document Schema view](https://docs.ravendb.net/assets/images/schema-validation_studio_audit-playground-375e86f68b007494e19cd0a55c7d4509.png)

- Use the playground to experiment with schema definitions and test them against documents in your collections.
- You can validate an entire collection or a specified number of documents.
- You can test multiple schemas in a single run, including multiple schemas for the same collection. This is helpful when you want to compare the effectiveness of different schema definitions, validate a specific field across collections, or test a large dataset.
- Test results are presented per schema, detailing the number and names of invalid documents and the validation error messages generated for each document.
- Find [here](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#the-schema-playground) a detailed explanation of the playground.

## Audit documents compliance by index {#audit-documents-compliance-by-index}

You can define an **audit index** that validates documents against a schema during indexing and stores any validation error messages in the index.

- The audit index can then be queried to find documents by compliance status and specific validation error messages.
- Indexing is performed continuously in the background, preparing for validation queries that remain quick and efficient even with large datasets.

> **Note**
>
> **Note** that disabling validation for the database or for the collection does **not** disable auditing by an index.

#### Define a validation schema

The index will use the schema defined in its index configuration.  
See how to add a schema to the index configuration [below](#create-the-audit-index).

- If no schema is defined in the index configuration, the index will use the [database-level schema](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#creating-a-collection-schema).
- If no schema is defined either in the index configuration or at the database level, the index will not perform any validation.

> **Note**
>
> **Note**: When the index uses a database-level schema, [disabling validation at the database level](https://docs.ravendb.net/7.2/documents/schema-validation/write-validation/write-validation_studio.md#managing-and-testing-existing-schemas) will also disable auditing by the index.  
> However, when the index uses an index-level schema, disabling database-level validation will **not** disable auditing by the index.

#### Create the audit index

To [create the index](https://docs.ravendb.net/7.2/studio/database/indexes/create-map-index.md), open **Indexes** > **List of indexes** and click the **New index** button.

- Name the index, and add to its map a call to the validation method: `Schema.GetErrorsFor()` for a static index, or `schema.getErrorsFor()` for a JavaScript map.  
  Assign the value returned by the validation method to a dedicated index field, e.g., `Errors`.

  ##### Static

  ```csharp
  from doc in docs
  let errors = Schema.GetErrorsFor(doc)
  where errors != null && errors.Length > 0
  select new 
  {
      Id = doc.Id,
      Errors = errors
  }
  ```

  ##### JavaScript

  ```javascript
  map("@all_docs", (doc) => { 
  let errors = schema.getErrorsFor(doc);
  if( errors != null && errors.length > 0)
      return {
          Id: id(doc),
          Errors: errors
      };
  })
  ```

- Add the validation error messages field (defined in the map) to the index.  
  Set the [Store](https://docs.ravendb.net/7.2/indexes/storing-data-in-index.md) option for this field to **Yes**, to store actual error messages in the index rather than just their tokens.

  ![Create audit index](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_create-index-17992df0122017cd9dce5c7bcfaea338.png)

- If you prefer that the index use an index-level schema, add it in the **Schema definition** tab.

  Open the **Schema definition** tab and add a new schema definition.
  ![Open index schema tab](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_schema-tab-5fea46e69e4f17323b01db81aecded84.png)

  Select a collection to associate the schema with, and define the schema using JSON syntax.
  ![Define index schema](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_schema-definition-d9ead4c56e661a478c4c99737b7bda86.png)

- When you're done, remember to save the index.

#### Query the index

Query the index to find documents by compliance status and specific error messages.

- While building or editing the index, you can use the **Test Index** bar to query the index and verify its functionality.  
  ![Run index test](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_test-index-80b6de64981ba456a1038268eb1fc082.png)

- Run queries that filter documents based on the `Errors` field.  
  ![Query audit index](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_test-index_results-2da0b111432b2c19aa312a5202aa0664.png)

  Click an item's preview (eye) icon to view the document details, including the validation error messages stored in the index.  
  ![See index entry](https://docs.ravendb.net/assets/images/schema-validation_studio_audit_index_test-index_results_preview-c71b68fe8da911796f00c44b728b574d.png)
