# AI use cases for Py Idp (rollroyces/py-idp)

Repo: [rollroyces/py-idp](https://github.com/rollroyces/py-idp) | Use cases: 4 | Page: https://dedupedai.com/use-cases/rollroyces-py-idp/

py-idp is an open-source Python library for intelligent document processing that uses LLM backends and Pydantic schemas to pull structured fields out of documents.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Extract invoice fields into a validated schema: https://dedupedai.com/use-cases/rollroyces-py-idp/extract-invoice-fields-to-pydantic/
- Route low-confidence fields to a human reviewer: https://dedupedai.com/use-cases/rollroyces-py-idp/review-low-confidence-fields-with-hitl/
- Measure extraction accuracy with the eval harness: https://dedupedai.com/use-cases/rollroyces-py-idp/measure-extraction-accuracy-with-eval/
- Serve document extraction through a FastAPI endpoint: https://dedupedai.com/use-cases/rollroyces-py-idp/serve-extraction-over-http-with-fastapi/

## How to extract invoice fields into a validated schema with Py Idp

Repo: [rollroyces/py-idp](https://github.com/rollroyces/py-idp) | Difficulty: Intermediate | Time: 30 minutes | Basis: From the README

Turn invoice PDFs into Pydantic-validated fields using one pipeline call or one CLI command.

**Who it is for:** A developer or finance ops engineer who receives a steady stream of invoice PDFs and needs the amounts, dates, and vendor names as clean data.

**The problem:** Writing a parser, chunker, and LLM prompt for every invoice layout takes time and breaks on new formats.

**The outcome:** A dict of extracted Invoice fields, checked against a Pydantic schema, with per-field confidence and any validation errors.

### Steps

1. Run `pip install py-idp` to install the core package. No API key is needed for this step.
2. Place invoice.pdf in the current directory and run `python examples/00_zero_to_extraction.py` to see extracted fields from the mock backend.
3. Run `export OPENAI_API_KEY=...` with your own key.
4. Run `idp run invoice.pdf --schema Invoice --backend openai` to extract the fields with a hosted model.

### Prompt to paste into your agent

```text
Using the py-idp repo, run the idp CLI on <path to invoice PDF> with --schema Invoice and --backend openai, then print the extracted fields. Verify that the output is a dict whose keys match the Invoice schema fields and that no validation errors are reported.
```

### Caveat

The zero-config path uses the mock backend, so real extraction quality only shows after you switch to a hosted or local LLM backend.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/rollroyces-py-idp/extract-invoice-fields-to-pydantic/

## How to route low-confidence fields to a human reviewer with Py Idp

Repo: [rollroyces/py-idp](https://github.com/rollroyces/py-idp) | Difficulty: Advanced | Time: 45 minutes | Basis: From the README

Send fields below the confidence threshold to a Streamlit review screen and save the corrections.

**Who it is for:** An operations lead running document extraction at volume who needs people to check the uncertain fields before the data is used.

**The problem:** Accepting every model output without review lets wrong amounts or dates reach downstream systems.

**The outcome:** Low-confidence documents are paused for review, and the saved corrections are stored for later use by the RL update step.

### Steps

1. Run `pip install py-idp` and confirm a document runs through the pipeline with `idp run invoice.pdf --schema Invoice --backend mock`. (inferred, check the README)
2. Start the Streamlit review app from the idp.hitl package. The README names the Streamlit review UI but does not give its launch command, so check the docs site for the exact command. (inferred, check the README)
3. Open the review screen, correct any flagged fields, and save the corrections.
4. Run `idp rl-update` to apply the saved corrections to the extraction policy.

### Prompt to paste into your agent

```text
In the py-idp repo, run one document through the pipeline and find which fields fall below the confidence threshold. Use the Streamlit HITL review screen to correct them, then confirm the corrections are saved in storage. Report the list of corrected fields.
```

### Caveat

The README names the Streamlit review UI but does not state its launch command, so the exact start step must be confirmed in the docs before use.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/rollroyces-py-idp/review-low-confidence-fields-with-hitl/

## How to measure extraction accuracy with the eval harness with Py Idp

Repo: [rollroyces/py-idp](https://github.com/rollroyces/py-idp) | Difficulty: Intermediate | Time: 45 minutes | Basis: From the README

Score a backend on field F1 and schema-valid rate before you trust it in production.

**Who it is for:** A developer comparing LLM backends or prompt changes who needs numbers before choosing one for a document workflow.

**The problem:** Judging extraction quality by reading a few outputs does not show how accuracy changes across fields or model versions.

**The outcome:** A per-field eval report with field F1 and schema-valid rate for the chosen backend.

### Steps

1. Run `pip install py-idp[eval]` to add the datasets and pandas packages that `idp eval` needs.
2. Run `idp eval` against your labeled documents, selecting the backend you want to compare.
3. Repeat the run with a second backend, such as `--backend ollama`, and keep the report from each run. (inferred, check the README)

### Prompt to paste into your agent

```text
In the py-idp repo, run `idp eval` on the labeled set at <path to eval data> using the <backend name> backend. Output the field F1 and schema-valid rate per field. Verify that the report lists every schema field.
```

### Caveat

The README does not list the exact flags for `idp eval` or the label format, so check the CLI help or docs before preparing your dataset.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/rollroyces-py-idp/measure-extraction-accuracy-with-eval/

## How to serve document extraction through a FastAPI endpoint with Py Idp

Repo: [rollroyces/py-idp](https://github.com/rollroyces/py-idp) | Difficulty: Advanced | Time: 45 minutes | Basis: From the README

Run the production FastAPI server so other systems can send documents and get fields back.

**Who it is for:** A backend developer who needs other internal services to submit documents over HTTP instead of running the Python library directly.

**The problem:** Each service that needs extraction would otherwise have to install and configure the pipeline on its own.

**The outcome:** A running HTTP server with /extract, /templates, /healthz, and /metrics endpoints.

### Steps

1. Run `pip install py-idp[api]` to install the FastAPI server extra.
2. Run `idp serve` to start the server. (inferred, check the README)
3. Send a document to the /extract endpoint with an HTTP client.
4. Call /healthz to confirm the server is up.

### Prompt to paste into your agent

```text
In the py-idp repo, start the FastAPI server with `idp serve`, then send <path to document> to the /extract endpoint. Return the JSON response. Verify that /healthz returns a healthy status before you send the document.
```

### Caveat

The README does not document the request format for /extract, so read the API docs before writing a client.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/rollroyces-py-idp/serve-extraction-over-http-with-fastapi/
