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

# Contract and policy memory

> Which clause, in which agreement, agreed when — with the provenance to prove where the answer came from.

[← All use cases](/use-cases/overview)

<div className="uc-examples"><a href="https://github.com/anonalabs/Anona-Memory-SDK/blob/main/examples/document_qa.py">document\_qa.py</a><a href="https://github.com/anonalabs/Anona-Memory-SDK/blob/main/examples/context_receipts.py">context\_receipts.py</a></div>

## The scenario

Someone asks whether the Acme contract lets them sublicense. The answer is in a
PDF, in a clause that amends another clause, in a folder with four versions of
the same agreement.

Getting it wrong is not a bad search result. It is a commercial exposure.

## Step 1 — Upload the agreements, tagged by counterparty

```python theme={null}
client.upload_file(
    space_id="contracts",
    file="acme-msa-2026.pdf",
    tags=["counterparty:acme", "type:msa"],
)
```

## Step 2 — Ask with the scope pinned

```python theme={null}
res = client.retrieve_receipt(
    space_id="contracts",
    query="sublicensing rights",
    tags=["counterparty:acme"],
    receipt_detail="full",
)
for row in res.memories:
    print(row["content"], "\n  from document", row.get("document_id"))
```

Every result carries the document it came from, so the answer is never
detached from its source.

## Step 3 — Keep the proof

```python theme={null}
receipt = client.get_receipt(res.receipt_id)
for cut in receipt["excluded"]:
    print("not shown:", cut["reason"], cut["detail"])
```

For legal work the *excluded* list matters as much as the results. A clause that
was found and cut for budget is a different situation from one that was never
matched — and only the receipt distinguishes them.

## Evals

1. Load two versions of the same agreement, one superseding the other.
2. Ask a question the two answer differently. Check which one comes back, and
   whether the other appears in the receipt's excluded list.
3. Ask about a counterparty you have no contract for. It must return nothing
   rather than the nearest other agreement.
4. Pick three answers and trace each to its `document_id` by hand. If any cannot
   be traced, stop using it for anything that matters.

## Guardrails

<Warning>
  **This does not give legal advice and must never be presented as doing so.**
  It finds and summarises text. A summary of a clause is not the clause, and a
  retrieval system has no view on which of two conflicting provisions governs.
  Route anything consequential to a lawyer with the source document attached.
</Warning>

* **Superseded versions stay retrievable unless you say otherwise.** That is
  usually right for contracts — but mark the old one explicitly with
  [a correction and a reason](/use-cases/correct-a-memory) so the status is
  recorded rather than inferred.
* **Never paste a clause into a prompt from memory alone** when the exact
  wording is operative. Use the result to find the document, then read it.
* **A receipt carries ids and reasons, never content**, which is what makes a
  receipt id safe to put in a ticket even when the underlying agreement is
  confidential.

## Built from

Both are complete, runnable scripts:
[`document_qa.py`](https://github.com/anonalabs/Anona-Memory-SDK/blob/main/examples/document_qa.py),
[`context_receipts.py`](https://github.com/anonalabs/Anona-Memory-SDK/blob/main/examples/context_receipts.py).
