> ## Documentation Index
> Fetch the complete documentation index at: https://agents.nanonets.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Compare

> Compares already-extracted documents and returns a structured match matrix (PO matching, invoice-vs-PO, 3-way).

Compares two or more already-extracted sides and returns a structured match matrix. Display name **"Compare"**. On by default for new agents.

This is the default for PO matching, invoice-vs-PO, 3-way match, or any "do these documents agree" job. Extract each side first (`structured_data_extraction`, or an ERP read). Then call `compare`. Do not use `ai_call` or `python_code_tool` just to diff extracted fields.

`decide_next_action` writes `prompt` every run. Two valid patterns:

1. **Compose the prompt** from prior step results already in history — both sides, tolerances, match rules — in citation form.
2. **Reference extraction variables** in the prompt (`Invoice:\n${VAR_2}\nPO:\n${VAR_3}`). The platform substitutes those tokens before the compare LLM runs.

The compare LLM does **not** see earlier chat. Put all required data in `prompt`.

Convert extracted fields to citation form:

* `{"quantity": {"value": 2, "word_id_groups": [7]}}` → `Quantity: 2[cite:7]`
* Never write `word_id_groups=[7]` in the prompt.

## Authentication and enablement

No integration. Uses the agent's LLM. Default-on. Applied learning rules for this comparison are injected by the orchestrator.

## Inputs

* `prompt` (required): the comparison, including both sides, match rules, and citation markers. May embed `${VAR_N}` references to prior `extracted_data` variables.

## Output

Primary output is `structuredContent` — a JSON comparison matrix, not a prose verdict.

* `Fields` — header rows (PO number, vendor, totals) with per-document values and `_row_meta.compare` (`status` + `reason`).
* `LineItem1` … `LineItemN` — one array per logical line. Each array is **row-per-document** with a `Source` field (`Invoice`, `PO`, `GRN`). Do not treat this as column-per-document.
* `_group_meta` — per-line status, `mismatch_columns`, and per-field verdicts under `fields`.
* `_doc_meta` — title, `documents[]` (name, icon, priority), and `comparison_summary`.

Status values: `match`, `mismatch`, `missing`. Every verdict includes a short `reason`. When a learned rule drove a verdict, the object also has `rule_id` (`rule-N`).

Step metadata holds provider, model, token counts, and `applied_memories`.

The task feed renders this matrix (`CompareFeedItem`) with match/mismatch badges and citation highlights when `word_id_groups` are present.

## PO / 3-way matching

1. Extract the invoice with `structured_data_extraction`.
2. Extract the PO file, or read it from the ERP (`read_sap_purchase_order`, …). For 3-way, also extract/read the GRN.
3. Call `compare` with a `prompt` that includes every side in citation form (composed by `decide_next_action`, or referenced via `${VAR_N}`).
4. Read the structured matrix for later review or writeback. Needing line-level JSON is not a reason to replace this tool with `ai_call`.

## Not a substitute for

* `structured_data_extraction` — extract fields first; compare does not read raw files.
* `llm_match` — fuzzy match one value against a synced catalog (vendor/item), not document-vs-document.
* `ai_call` — generic enrichment (coding, mapping, summaries). Not invoice-vs-PO.

Compare has no configured-tool bindings. An optional display-name alias still executes this native tool; call the base name `compare` if learned-rule forwarding should apply.

## Limits and side effects

* One LLM call per invocation. No external writes.
* Large prompts are accepted (`MaxTokens` is high); billed per call plus tokens.

## Expected errors

* Empty `prompt`.
* Provider failure.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.