Metadata-Version: 2.5
Name: langchain-pandex
Version: 0.1.0
Summary: LangChain tools for Pandex: search and read official law and case law from 25 countries and the EU
Project-URL: Homepage, https://www.pandex.io
Project-URL: Documentation, https://docs.pandex.io
Project-URL: Repository, https://github.com/pandex-io/langchain-pandex
Project-URL: Free key, https://www.pandex.io/key
Author-email: Pandex <vasco@pandex.io>
License-Expression: MIT
License-File: LICENSE
Keywords: ai agents,case law,langchain,law,legal,legislation,tools
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Legal Industry
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: langchain-core<2.0.0,>=0.3.0
Requires-Dist: pandex>=0.1.0
Description-Content-Type: text/markdown

# langchain-pandex

LangChain tools for [Pandex](https://www.pandex.io): search and read official law and case law from 25 countries and the EU, in the official wording, as it stood on any date, with the decisions that cite it.

| Tool | Name the model sees | What it does |
| --- | --- | --- |
| `PandexSearch` | `pandex_search` | Find passages of legislation and court decisions: words, a question, or a citation such as "§ 823 BGB" or an ECLI |
| `PandexDocument` | `pandex_document` | Read a law, one article of it, or a decision; `at` reads the wording in force on a past day |
| `PandexCitations` | `pandex_citations` | What cites a law, an article or a decision, the leading ones first (or what it cites) |

Each tool returns the answer as text written for a model to read, the same text the [Pandex MCP server](https://docs.pandex.io) gives. They are built on the [`pandex`](https://github.com/pandex-io/pandex-python) client; sync and async both work.

## Install

```
pip install langchain-pandex
export PANDEX_API_KEY=px_...   # free key: https://www.pandex.io/key
```

Without a key the tools still work, with 50 calls a day per address.

## Use the tools directly

```python
from langchain_pandex import PandexCitations, PandexDocument, PandexSearch

search = PandexSearch()   # or PandexSearch(api_key="px_...")
print(search.invoke({"query": "right to erasure personal data", "jurisdiction": "eu", "kind": "legislation", "limit": 3}))

document = PandexDocument()
print(document.invoke({"id": "Code civil", "element": "1382", "at": "2015-01-01"}))
```

```
Code civil
code · 1804-03-21 · in force 1804-03-21– · fr · cited by 219346
id fr.dila_legi:LEGITEXT000006070721 · legifrance=LEGITEXT000006070721
https://www.legifrance.gouv.fr/loda/id/LEGITEXT000006070721

Livre III : Des différentes manières dont on acquiert la propriété › Titre IV : Des engagements qui se forment sans convention › Chapitre II : Des délits et des quasi-délits.
[art_1382] article 1382 (wording in force 1804-03-21–2016-10-01)
Tout fait quelconque de l'homme, qui cause à autrui un dommage, oblige celui par la faute duquel il est arrivé à le réparer.

Cited by 28493 decisions; the ones they cite most:
...
```

```python
citations = PandexCitations()
print(citations.invoke({"id": "32016R0679", "element": "art_17", "limit": 3}))
```

```
Regulation (EU) 2016/679 ... (General Data Protection Regulation) ... art_17 [eu.legislation:32016R0679] is cited by 73 documents:
- 2022-02-24 CJ: Judgment of the Court (Fifth Chamber) of 24 February 2022. SIA 'SS' v Valsts ieņēmumu dienests. ... [eu.caselaw:62020CJ0175] at p_51, p_61 · cited by 12 of them
  "However, Article 23 of Regulation 2016/679 authorises the European Union and Member States to adopt a ‘legislative measure’ ..."
...
```

## Use them in an agent

```python
from langchain.agents import create_agent
from langchain_pandex import PandexCitations, PandexDocument, PandexSearch

agent = create_agent(
    "anthropic:claude-opus-5-5",   # any chat model with tool calling
    tools=[PandexSearch(), PandexDocument(), PandexCitations()],
    system_prompt=(
        "You answer questions on the law with the Pandex tools. Quote the official wording, "
        "name each text by its id and article, and say when you could not find something."
    ),
)
result = agent.invoke({"messages": [{"role": "user", "content": "What did article 1382 of the French Code civil say in 2015, and which decisions cite it most?"}]})
print(result["messages"][-1].text)
```

## Arguments

- `PandexSearch`: `query`, and optionally `jurisdiction` (`"eu"`, `"de"`, `"fr,be"`...), `kind` (`legislation`, `decision`, `treaty`), `court`, `date_from`, `date_to`, `at`, `limit`.
- `PandexDocument`: `id` (a result id, or a citation: `"BGB"`, `"art. 6:162 BW"`, an ECLI, a CELEX number), and optionally `element`, `at`, `history`, `continue_from`, `max_tokens`.
- `PandexCitations`: `id`, and optionally `element`, `direction` (`in`, `out`), `order` (`leading`, `newest`), `limit`.

Coverage, per country and source: https://www.pandex.io/coverage. The full API: https://docs.pandex.io.

## Tests

```
pip install -e . pytest pytest-asyncio langchain-tests
pytest tests/unit_tests
PANDEX_API_KEY=px_... pytest tests/integration_tests   # calls the live API
```

The tools pass LangChain's standard `ToolsUnitTests` and `ToolsIntegrationTests`.

## Licence

MIT. Maintained by Pandex.
