> For the complete documentation index, see [llms.txt](https://docs.guardianservice.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.guardianservice.app/technical-information/users/standard-registry-users-schemas-and-policies/policies/available-policy-workflow-blocks/documentvalidatorblock/document-validator-block-source-validations.md).

# Document Validator Block Source Validations

Check an incoming document against other documents already in the database.

Source Validations let a `documentValidatorBlock` verify that a related document already exists, and that specific fields on that document satisfy conditions defined against the incoming document, before the workflow is allowed to proceed.

## The problem it solves

Many MRV workflows depend on sequencing. A monitoring report is only valid after a project registration has been approved. An emission reduction claim must reference a methodology document already on record, or must be checked against dates on a document found by project ID. Without a cross-document check at the block level, enforcing that ordering means a custom logic block or a manual review gate, both of which add complexity and surface area for errors.

Source Validations move that responsibility into `documentValidatorBlock` itself. The block queries for documents matching a schema and ownership criteria, then tests field-level conditions spanning both the incoming document and the results, routing the event to the error output if the check fails.

## How it works

A `documentValidatorBlock` can hold any number of Source Validation entries under **Source Validations**. Each entry is evaluated independently, in order.

### Query phase

The block builds a database filter from the entry's configuration:

| Setting                                                                            | Effect                                                                                                                 |
| ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **Source Collection**                                                              | Whether to query **VC Document** or **VP Document** records.                                                           |
| **Schema**                                                                         | Restricts the query to documents matching a specific schema.                                                           |
| **Owned by User**, **Owned by Group**, **Assigned to User**, **Assigned to Group** | Optionally limit results to documents owned by or assigned to the current user or their group.                         |
| **Source Filters**                                                                 | Field-level conditions on the source documents themselves, for example `credentialSubject.0.status` equals `Approved`. |

Each **Source Filter** has a **Field**, an **Operator**, a **Value Type**, and a **Value**. Value Type chooses whether the comparison value is a literal (**Value**) or is read from the incoming document (**Variable (Input Doc)**).

### Condition phase

Once the query returns a set of candidate documents, each one is tested against the entry's **Conditions**. A condition has two sides:

* **Left Source** is either **Value** or **Input Document**, with **Left Field** naming the path when it is a document.
* **Right Source** is **Value**, **Input Document**, or **Source Document**, with **Right Field** naming the path.

Supported operators are Equal, Not Equal, In, Not In, Greater Than, Greater Than or Equal, Less Than, and Less Than or Equal.

### Pass and fail

The entry passes if **at least one** candidate document satisfies **all** of its conditions. If the query returns no documents, or every candidate fails at least one condition, the entry fails.

On failure the block builds a message describing which conditions failed and on how many source documents. If a **Fail Message** is set on the entry, it is placed in front of that detail. The error routes the event to the block's error output.

### Where this sits in the block's validation sequence

A document is checked in this order, and the first failure stops evaluation and emits the error event:

1. Document existence
2. Document type: VC Document, VP Document, Related VC Document, or Related VP Document
3. Ownership checks, by user and by group
4. Assignment checks, by user and by group
5. Organization checks, on the owner organization and the assignee organization
6. Schema validation
7. **Conditions**, meaning field conditions on the incoming document only
8. **Source Validations**, one entry at a time

## Key distinctions

**Conditions and Source Validations.** The block has two separate condition mechanisms. The top-level **Conditions** array checks fields on the incoming document only, with no database query. **Source Validations** query the database and then compare fields across two documents. Use top-level Conditions for simple field checks, and Source Validations when the check depends on the state of another document.

**Source Filters and Source Validation Conditions.** Within an entry, **Source Filters** narrow the query and decide which documents are candidates. **Conditions** test the relationship between a candidate and the incoming document after the query returns. Filters reduce the candidate set; conditions decide whether any candidate in that set is sufficient.

**Pass if any, not pass if all.** The entry passes as soon as one candidate satisfies all conditions. It does not require every queried document to satisfy them.

## Related

* Task: [Configure Source Validations](/technical-information/users/standard-registry-users-schemas-and-policies/policies/available-policy-workflow-blocks/documentvalidatorblock/configure-source-validations.md)
* Reference: [documentValidatorBlock](/technical-information/users/standard-registry-users-schemas-and-policies/policies/available-policy-workflow-blocks/documentvalidatorblock.md)
* Concept: [Policy Configurator](/technical-information/users/standard-registry-users-schemas-and-policies/policies/policy-configurator.md)
