> ## Documentation Index
> Fetch the complete documentation index at: https://uom-demo.vercel.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# query_validator

> [<span className="flex items-center gap-1"><Icon icon="external-link"/>View Source</span>](https://github.com/corovcam/Universal-Object-Mapping/tree/main/services/orchestrator/src/react_agent/custom_tools/query_validator.py)

Query validation and equivalence tools for source and target query execution metadata.

This module provides Pydantic models for inputs and LangChain tool definitions that facilitate
the execution and semantic equivalence comparison of source-side and target-side database queries.
Semantic equivalence is computed using the `DeepDiff` library to compare query output metrics
such as row counts and data samples, with tolerance for sorting differences and precision variances.

## react\_agent.custom\_tools.query\_validator.SourceQueryInput Objects

```python theme={null}
class SourceQueryInput(BaseModel)
```

[<span className="flex items-center gap-1"><Icon icon="external-link" />View Source</span>](https://github.com/corovcam/Universal-Object-Mapping/blob/main/services/orchestrator/src/react_agent/custom_tools/query_validator.py#L36)

Input payload for validating source-side schema/queries in .NET environments.

**Attributes**:

* `validation_schema_code` - Source schema validation code containing imports,
  initialization, context setup, and minor fetch validation logic.
* `validation_harness_code` - Runnable execution harness code that runs the C# LINQ
  queries, captures count/samples, and writes the structured output JSON.
* `source_framework` - The relational source framework target (e.g. EF Core, Dapper).
* `entry_type_name` - Declared main class/type name containing the entry point.
* `entry_method_name` - Declared main static method name serving as execution entry.

## react\_agent.custom\_tools.query\_validator.TargetQueryInput Objects

```python theme={null}
class TargetQueryInput(BaseModel)
```

[<span className="flex items-center gap-1"><Icon icon="external-link" />View Source</span>](https://github.com/corovcam/Universal-Object-Mapping/blob/main/services/orchestrator/src/react_agent/custom_tools/query_validator.py#L71)

Input payload for validating target-side schema/queries in Java environments.

**Attributes**:

* `validation_schema_code` - Target schema validation code containing imports,
  bootstrapping, entity annotations, and driver configuration.
* `validation_harness_code` - Runnable execution harness code that runs the Java MongoDB/Neo4j
  queries, captures count/samples, and writes the structured output JSON.
* `target_framework` - The target framework target (e.g. Spring Data MongoDB, Spring Data Neo4j).
* `entry_type_name` - Declared main public class name containing the entry point.
* `entry_method_name` - Declared main static method name serving as execution entry.

## react\_agent.custom\_tools.query\_validator.QueryEquivalenceInput Objects

```python theme={null}
class QueryEquivalenceInput(BaseModel)
```

[<span className="flex items-center gap-1"><Icon icon="external-link" />View Source</span>](https://github.com/corovcam/Universal-Object-Mapping/blob/main/services/orchestrator/src/react_agent/custom_tools/query_validator.py#L104)

Input payload for comparing source and target query outputs for equivalence.

**Attributes**:

* `source_validation_output` - Text/log output produced by executing source validation.
* `target_validation_output` - Text/log output produced by executing target validation.

#### react\_agent.custom\_tools.query\_validator.check\_query\_equivalence

```python theme={null}
@tool
async def check_query_equivalence(source_validation_output: str,
                                  target_validation_output: str,
                                  runtime: ToolRuntime) -> Command | str
```

[<span className="flex items-center gap-1"><Icon icon="external-link" />View Source</span>](https://github.com/corovcam/Universal-Object-Mapping/blob/main/services/orchestrator/src/react_agent/custom_tools/query_validator.py#L156)

Compare source C#/.NET and target Java query execution outputs to verify logical equivalence.

This tool acts as a semantic validation gate. It retrieves the JSON outputs stored in the state,
identifies common queries, and uses `DeepDiff` to evaluate whether they returned identical counts
and matching records.

It implements a robust sorting-tolerant comparison logic (swapped orders) to prevent false-positives
when database drivers iterate or sort query datasets differently under relational vs NoSQL engines.

**Arguments**:

* `source_validation_output` - String output logging from source validation tool.
* `target_validation_output` - String output logging from target validation tool.
* `runtime` - Injected LangChain ToolRuntime context to access state and configuration.

**Returns**:

Command | str: A LangGraph Command updating the equivalence diff state and adding
a ToolMessage, or an error string if validation markers are violated.
