sidx 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sidx-0.0.3/PKG-INFO ADDED
@@ -0,0 +1,152 @@
1
+ Metadata-Version: 2.4
2
+ Name: sidx
3
+ Version: 0.0.3
4
+ Summary: A multi-stage agentic framework for extracting structured data from documents
5
+ Keywords: llm,agents,data-extraction,document-extraction,pydantic-ai,docling
6
+ Author: Andy Tseng
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 2 - Pre-Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Typing :: Typed
14
+ Requires-Dist: docling>=2.151.1
15
+ Requires-Dist: pydantic-ai>=2.71.0
16
+ Requires-Python: >=3.13
17
+ Project-URL: Homepage, https://github.com/ohandyya/self-improving-data-extraction
18
+ Project-URL: Repository, https://github.com/ohandyya/self-improving-data-extraction
19
+ Description-Content-Type: text/markdown
20
+
21
+ # sidx
22
+
23
+ **S**elf-**i**mproving **d**ata e**x**traction: pull structured fields out of
24
+ a PDF with LLMs, where every answer comes with quotes from the document that
25
+ code has checked, and a reviewer model sends doubtful answers back for
26
+ another try. Built on [PydanticAI](https://ai.pydantic.dev) and
27
+ [Docling](https://github.com/docling-project/docling).
28
+
29
+ > **Work in progress.** There is no extraction code yet. This page shows the
30
+ > planned API from the design in [`docs/design/`](./docs/design/).
31
+
32
+ ## What it does
33
+
34
+ You describe the fields you want. For each one, sidx gives back:
35
+
36
+ - **a value**, checked against the type and limits you set, or a reason
37
+ there is none (`NOT_FOUND`, `AMBIGUOUS`, ...);
38
+ - **evidence**: quotes copied from the document, with the PDF pages they
39
+ are on. Code confirms every quote really is in the document;
40
+ - **`agreement`**: how many of the extractor models gave the same answer;
41
+ - **`confidence`**: the reviewer model's judgement of the answer.
42
+
43
+ Each result also reports the **tokens and estimated cost** of the call,
44
+ split between extractors and reviewer.
45
+
46
+ ### What is guaranteed, and what is not
47
+
48
+ sidx separates what **code** checks from what a **model** judges. Code
49
+ checks hold for every result; if a model cannot meet them after its retries,
50
+ the field is marked as failed rather than returned unchecked. Everything in
51
+ the right-hand column is a model's judgement (or, for usage, the provider's
52
+ and the price list's numbers) and nothing in sidx verifies it.
53
+
54
+ | Output | Guaranteed by code | Not guaranteed |
55
+ |---|---|---|
56
+ | `fields` | Exactly one result per field you asked for, in your order. | — |
57
+ | `value` | Valid for the field's type and limits. Taken unchanged from one extractor's answer; the reviewer only picks, never writes. | That it is **correct**. |
58
+ | `null_reason_code` | Set exactly when `value` is empty. | That the document really lacks the value (`NOT_FOUND`) or is really unclear (`AMBIGUOUS`). |
59
+ | `evidence` | Every value has at least one quote. Every quote occurs exactly once in the document; the text and page numbers are copied from the document by code. | That the quote actually **supports** the value. |
60
+ | `agreement` | Computed by code: the share of extractors whose answer equals the accepted one. | That agreement means correctness: extractors using the same model can share a mistake. |
61
+ | `confidence` | Between 0 and 1. | That it is calibrated, or comparable across fields or runs. |
62
+ | `usage` | Every model request is counted once, retries and failed runs included, and the parts add up. A cost that cannot be fully priced is `None`, never a partial sum. | Exact token counts (they are what the provider reports) and the real bill (cost is estimated from the installed price list). |
63
+
64
+ Docling's conversion is not checked either: if it misreads a table or a
65
+ scanned page, the extractors see what it produced. The full lists are in
66
+ [`docs/design/interface.md`](./docs/design/interface.md#what-code-guarantees).
67
+
68
+ ## Quick start
69
+
70
+ ```sh
71
+ pip install sidx # or: uv add sidx
72
+ export OPENAI_API_KEY=... # the key for whichever provider your models use
73
+ ```
74
+
75
+ ```python
76
+ import asyncio
77
+
78
+ import sidx
79
+
80
+ MODEL = "openai:<model-name>" # any pydantic-ai model string
81
+
82
+ fields = [
83
+ sidx.FieldSpec(
84
+ name="eligibility_service_months",
85
+ type="int",
86
+ description="Months of service an employee needs before joining the plan.",
87
+ minimum=0,
88
+ ),
89
+ ]
90
+ config = sidx.ExtractionConfig(
91
+ extractor_models=[MODEL] * 3, # three extractors; models may differ
92
+ reviewer_model=MODEL,
93
+ )
94
+
95
+ result = asyncio.run(sidx.extract("plan.pdf", fields, config))
96
+
97
+ for field in result.fields:
98
+ print(field.name, field.value, field.null_reason_code, field.confidence)
99
+ for evidence in field.evidence:
100
+ print(f" pages {evidence.pages}: {evidence.text}")
101
+ print("cost (USD):", result.usage.total.cost_usd)
102
+ ```
103
+
104
+ ## How it works
105
+
106
+ ```mermaid
107
+ flowchart LR
108
+ pdf[/"PDF"/] --> conv["Docling<br/>PDF → markdown"]
109
+ fields[/"Your fields"/] --> start(["Document + fields"])
110
+ conv --> start
111
+
112
+ subgraph ext ["Extractors: run in parallel, independently"]
113
+ direction TB
114
+ e1["Extractor 1"]
115
+ e2["Extractor 2"]
116
+ e3["Extractor N"]
117
+ end
118
+
119
+ start --> e1 & e2 & e3
120
+ e1 & e2 & e3 -- "value + quotes<br/>per field" --> check["Code checks:<br/>types and limits,<br/>quotes are in the document"]
121
+ check --> rev["Reviewer LLM:<br/>accept one answer per field,<br/>or reject it with a comment"]
122
+ rev -- "rejected fields + comments<br/>(up to max_rounds)" --> start
123
+ rev -- "accepted fields" --> out[/"Result: value, evidence + pages,<br/>agreement, confidence, usage"/]
124
+ ```
125
+
126
+ 1. **Convert.** Docling turns the PDF into markdown, page by page.
127
+ 2. **Extract.** Several extractors answer every field independently, each
128
+ with quotes as evidence. Code rejects any answer whose value breaks your
129
+ limits or whose quotes are not in the document, and the model tries
130
+ again.
131
+ 3. **Review.** A reviewer model looks at all the answers for each field and
132
+ accepts one, or rejects the field with a comment saying what was wrong.
133
+ It never writes a value itself, so every accepted value came from an
134
+ extractor with checked evidence.
135
+ 4. **Re-extract.** Rejected fields go back to the extractors with the
136
+ reviewer's comments, up to `max_rounds`. A field still rejected at the end
137
+ comes back with no value and the reviewer's last comment.
138
+
139
+ The full design, including exactly what code guarantees and what it does
140
+ not, is in [`docs/design/interface.md`](./docs/design/interface.md) and
141
+ [`docs/design/pipeline.md`](./docs/design/pipeline.md).
142
+
143
+ ## Contributing
144
+
145
+ Setup, development commands, the source documents used for testing, and the
146
+ release process are in [`CONTRIBUTING.md`](./CONTRIBUTING.md).
147
+
148
+ ## License
149
+
150
+ [MIT](./LICENSE), covering the code and docs in this repo. The plan document
151
+ PDFs used for development belong to their respective publishers and are not
152
+ covered by it.
sidx-0.0.3/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # sidx
2
+
3
+ **S**elf-**i**mproving **d**ata e**x**traction: pull structured fields out of
4
+ a PDF with LLMs, where every answer comes with quotes from the document that
5
+ code has checked, and a reviewer model sends doubtful answers back for
6
+ another try. Built on [PydanticAI](https://ai.pydantic.dev) and
7
+ [Docling](https://github.com/docling-project/docling).
8
+
9
+ > **Work in progress.** There is no extraction code yet. This page shows the
10
+ > planned API from the design in [`docs/design/`](./docs/design/).
11
+
12
+ ## What it does
13
+
14
+ You describe the fields you want. For each one, sidx gives back:
15
+
16
+ - **a value**, checked against the type and limits you set, or a reason
17
+ there is none (`NOT_FOUND`, `AMBIGUOUS`, ...);
18
+ - **evidence**: quotes copied from the document, with the PDF pages they
19
+ are on. Code confirms every quote really is in the document;
20
+ - **`agreement`**: how many of the extractor models gave the same answer;
21
+ - **`confidence`**: the reviewer model's judgement of the answer.
22
+
23
+ Each result also reports the **tokens and estimated cost** of the call,
24
+ split between extractors and reviewer.
25
+
26
+ ### What is guaranteed, and what is not
27
+
28
+ sidx separates what **code** checks from what a **model** judges. Code
29
+ checks hold for every result; if a model cannot meet them after its retries,
30
+ the field is marked as failed rather than returned unchecked. Everything in
31
+ the right-hand column is a model's judgement (or, for usage, the provider's
32
+ and the price list's numbers) and nothing in sidx verifies it.
33
+
34
+ | Output | Guaranteed by code | Not guaranteed |
35
+ |---|---|---|
36
+ | `fields` | Exactly one result per field you asked for, in your order. | — |
37
+ | `value` | Valid for the field's type and limits. Taken unchanged from one extractor's answer; the reviewer only picks, never writes. | That it is **correct**. |
38
+ | `null_reason_code` | Set exactly when `value` is empty. | That the document really lacks the value (`NOT_FOUND`) or is really unclear (`AMBIGUOUS`). |
39
+ | `evidence` | Every value has at least one quote. Every quote occurs exactly once in the document; the text and page numbers are copied from the document by code. | That the quote actually **supports** the value. |
40
+ | `agreement` | Computed by code: the share of extractors whose answer equals the accepted one. | That agreement means correctness: extractors using the same model can share a mistake. |
41
+ | `confidence` | Between 0 and 1. | That it is calibrated, or comparable across fields or runs. |
42
+ | `usage` | Every model request is counted once, retries and failed runs included, and the parts add up. A cost that cannot be fully priced is `None`, never a partial sum. | Exact token counts (they are what the provider reports) and the real bill (cost is estimated from the installed price list). |
43
+
44
+ Docling's conversion is not checked either: if it misreads a table or a
45
+ scanned page, the extractors see what it produced. The full lists are in
46
+ [`docs/design/interface.md`](./docs/design/interface.md#what-code-guarantees).
47
+
48
+ ## Quick start
49
+
50
+ ```sh
51
+ pip install sidx # or: uv add sidx
52
+ export OPENAI_API_KEY=... # the key for whichever provider your models use
53
+ ```
54
+
55
+ ```python
56
+ import asyncio
57
+
58
+ import sidx
59
+
60
+ MODEL = "openai:<model-name>" # any pydantic-ai model string
61
+
62
+ fields = [
63
+ sidx.FieldSpec(
64
+ name="eligibility_service_months",
65
+ type="int",
66
+ description="Months of service an employee needs before joining the plan.",
67
+ minimum=0,
68
+ ),
69
+ ]
70
+ config = sidx.ExtractionConfig(
71
+ extractor_models=[MODEL] * 3, # three extractors; models may differ
72
+ reviewer_model=MODEL,
73
+ )
74
+
75
+ result = asyncio.run(sidx.extract("plan.pdf", fields, config))
76
+
77
+ for field in result.fields:
78
+ print(field.name, field.value, field.null_reason_code, field.confidence)
79
+ for evidence in field.evidence:
80
+ print(f" pages {evidence.pages}: {evidence.text}")
81
+ print("cost (USD):", result.usage.total.cost_usd)
82
+ ```
83
+
84
+ ## How it works
85
+
86
+ ```mermaid
87
+ flowchart LR
88
+ pdf[/"PDF"/] --> conv["Docling<br/>PDF → markdown"]
89
+ fields[/"Your fields"/] --> start(["Document + fields"])
90
+ conv --> start
91
+
92
+ subgraph ext ["Extractors: run in parallel, independently"]
93
+ direction TB
94
+ e1["Extractor 1"]
95
+ e2["Extractor 2"]
96
+ e3["Extractor N"]
97
+ end
98
+
99
+ start --> e1 & e2 & e3
100
+ e1 & e2 & e3 -- "value + quotes<br/>per field" --> check["Code checks:<br/>types and limits,<br/>quotes are in the document"]
101
+ check --> rev["Reviewer LLM:<br/>accept one answer per field,<br/>or reject it with a comment"]
102
+ rev -- "rejected fields + comments<br/>(up to max_rounds)" --> start
103
+ rev -- "accepted fields" --> out[/"Result: value, evidence + pages,<br/>agreement, confidence, usage"/]
104
+ ```
105
+
106
+ 1. **Convert.** Docling turns the PDF into markdown, page by page.
107
+ 2. **Extract.** Several extractors answer every field independently, each
108
+ with quotes as evidence. Code rejects any answer whose value breaks your
109
+ limits or whose quotes are not in the document, and the model tries
110
+ again.
111
+ 3. **Review.** A reviewer model looks at all the answers for each field and
112
+ accepts one, or rejects the field with a comment saying what was wrong.
113
+ It never writes a value itself, so every accepted value came from an
114
+ extractor with checked evidence.
115
+ 4. **Re-extract.** Rejected fields go back to the extractors with the
116
+ reviewer's comments, up to `max_rounds`. A field still rejected at the end
117
+ comes back with no value and the reviewer's last comment.
118
+
119
+ The full design, including exactly what code guarantees and what it does
120
+ not, is in [`docs/design/interface.md`](./docs/design/interface.md) and
121
+ [`docs/design/pipeline.md`](./docs/design/pipeline.md).
122
+
123
+ ## Contributing
124
+
125
+ Setup, development commands, the source documents used for testing, and the
126
+ release process are in [`CONTRIBUTING.md`](./CONTRIBUTING.md).
127
+
128
+ ## License
129
+
130
+ [MIT](./LICENSE), covering the code and docs in this repo. The plan document
131
+ PDFs used for development belong to their respective publishers and are not
132
+ covered by it.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sidx"
3
- version = "0.0.2"
3
+ version = "0.0.3"
4
4
  description = "A multi-stage agentic framework for extracting structured data from documents"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sidx"
3
- version = "0.0.2"
3
+ version = "0.0.3"
4
4
  description = "A multi-stage agentic framework for extracting structured data from documents"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
sidx-0.0.2/PKG-INFO DELETED
@@ -1,98 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sidx
3
- Version: 0.0.2
4
- Summary: A multi-stage agentic framework for extracting structured data from documents
5
- Keywords: llm,agents,data-extraction,document-extraction,pydantic-ai,docling
6
- Author: Andy Tseng
7
- License-Expression: MIT
8
- License-File: LICENSE
9
- Classifier: Development Status :: 2 - Pre-Alpha
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Typing :: Typed
14
- Requires-Dist: docling>=2.151.1
15
- Requires-Dist: pydantic-ai>=2.71.0
16
- Requires-Python: >=3.13
17
- Project-URL: Homepage, https://github.com/ohandyya/self-improving-data-extraction
18
- Project-URL: Repository, https://github.com/ohandyya/self-improving-data-extraction
19
- Description-Content-Type: text/markdown
20
-
21
- # sidx
22
-
23
- **S**elf-**i**mproving **d**ata e**x**traction: a multi-stage agentic framework
24
- for extracting structured data from documents, built on
25
- [PydanticAI](https://ai.pydantic.dev) and
26
- [Docling](https://github.com/docling-project/docling).
27
-
28
- > **Work in progress.** There is no extraction code yet. The design is being
29
- > written in [`docs/design/`](./docs/design/).
30
-
31
- The first source documents are 401(k) basic plan documents from three
32
- providers. Each one lays out the same material differently, which makes them
33
- a test of whether extraction holds up across layouts. See
34
- [`resources/plan_documents/`](./resources/plan_documents/README.md).
35
-
36
- ## Setup
37
-
38
- Requires [uv](https://docs.astral.sh/uv/). Python 3.13 is installed by uv if
39
- you don't have it.
40
-
41
- ```sh
42
- uv sync # install dependencies into .venv
43
- make hooks # install the pre-commit hook, once per clone
44
- uv run python scripts/download_plan_documents.py # fetch the source PDFs
45
- ```
46
-
47
- The source PDFs are copyrighted by their publishers, so they are not committed
48
- here. The download script fetches each one from its original URL and checks it
49
- against a pinned SHA-256.
50
-
51
- To call a model, copy `.env.example` to `.env` and fill in the values. Each
52
- variable is described in `.env.example`.
53
-
54
- ## Development
55
-
56
- ```sh
57
- make help # list every target
58
- make check-all # ruff lint, ruff format check, pyright — what CI runs
59
- make fix # auto-fix lint errors
60
- make format # reformat code
61
- ```
62
-
63
- [`CONTRIBUTING.md`](./CONTRIBUTING.md) covers the PR checklist and how releases
64
- are published to PyPI.
65
-
66
- | Path | What's there |
67
- |---|---|
68
- | `src/sidx/` | The package (`import sidx`) |
69
- | `scripts/` | One-off tooling, such as the PDF download script |
70
- | `resources/plan_documents/` | Source documents (downloaded, not committed) and notes on them |
71
- | `docs/design/` | How the system is meant to work — the spec |
72
- | `docs/implementations/` | The build plan, one doc per PR |
73
-
74
- ## Cutting a release
75
-
76
- Releases are published to PyPI by GitHub Actions, never from a laptop.
77
-
78
- 1. **Check you're ready.** From an up-to-date `main` with a clean working tree:
79
-
80
- ```sh
81
- git switch main && git pull
82
- make release-check # add VERSION=X.Y.Z to check that version is free
83
- ```
84
-
85
- It changes nothing. Fix any `FAIL` line before going on.
86
-
87
- 2. **Run the release.** In Claude Code, run `/create-new-release`. It proposes
88
- the next version for you to confirm, merges a release PR with the version
89
- bump and changelog, tags it, publishes the GitHub release, and checks that
90
- PyPI has the new version.
91
-
92
- The one-time PyPI and GitHub setup, and how to release by hand, are in
93
- [`CONTRIBUTING.md`](./CONTRIBUTING.md#releasing).
94
-
95
- ## License
96
-
97
- [MIT](./LICENSE), covering the code and docs in this repo. The plan document
98
- PDFs belong to their respective publishers and are not covered by it.
sidx-0.0.2/README.md DELETED
@@ -1,78 +0,0 @@
1
- # sidx
2
-
3
- **S**elf-**i**mproving **d**ata e**x**traction: a multi-stage agentic framework
4
- for extracting structured data from documents, built on
5
- [PydanticAI](https://ai.pydantic.dev) and
6
- [Docling](https://github.com/docling-project/docling).
7
-
8
- > **Work in progress.** There is no extraction code yet. The design is being
9
- > written in [`docs/design/`](./docs/design/).
10
-
11
- The first source documents are 401(k) basic plan documents from three
12
- providers. Each one lays out the same material differently, which makes them
13
- a test of whether extraction holds up across layouts. See
14
- [`resources/plan_documents/`](./resources/plan_documents/README.md).
15
-
16
- ## Setup
17
-
18
- Requires [uv](https://docs.astral.sh/uv/). Python 3.13 is installed by uv if
19
- you don't have it.
20
-
21
- ```sh
22
- uv sync # install dependencies into .venv
23
- make hooks # install the pre-commit hook, once per clone
24
- uv run python scripts/download_plan_documents.py # fetch the source PDFs
25
- ```
26
-
27
- The source PDFs are copyrighted by their publishers, so they are not committed
28
- here. The download script fetches each one from its original URL and checks it
29
- against a pinned SHA-256.
30
-
31
- To call a model, copy `.env.example` to `.env` and fill in the values. Each
32
- variable is described in `.env.example`.
33
-
34
- ## Development
35
-
36
- ```sh
37
- make help # list every target
38
- make check-all # ruff lint, ruff format check, pyright — what CI runs
39
- make fix # auto-fix lint errors
40
- make format # reformat code
41
- ```
42
-
43
- [`CONTRIBUTING.md`](./CONTRIBUTING.md) covers the PR checklist and how releases
44
- are published to PyPI.
45
-
46
- | Path | What's there |
47
- |---|---|
48
- | `src/sidx/` | The package (`import sidx`) |
49
- | `scripts/` | One-off tooling, such as the PDF download script |
50
- | `resources/plan_documents/` | Source documents (downloaded, not committed) and notes on them |
51
- | `docs/design/` | How the system is meant to work — the spec |
52
- | `docs/implementations/` | The build plan, one doc per PR |
53
-
54
- ## Cutting a release
55
-
56
- Releases are published to PyPI by GitHub Actions, never from a laptop.
57
-
58
- 1. **Check you're ready.** From an up-to-date `main` with a clean working tree:
59
-
60
- ```sh
61
- git switch main && git pull
62
- make release-check # add VERSION=X.Y.Z to check that version is free
63
- ```
64
-
65
- It changes nothing. Fix any `FAIL` line before going on.
66
-
67
- 2. **Run the release.** In Claude Code, run `/create-new-release`. It proposes
68
- the next version for you to confirm, merges a release PR with the version
69
- bump and changelog, tags it, publishes the GitHub release, and checks that
70
- PyPI has the new version.
71
-
72
- The one-time PyPI and GitHub setup, and how to release by hand, are in
73
- [`CONTRIBUTING.md`](./CONTRIBUTING.md#releasing).
74
-
75
- ## License
76
-
77
- [MIT](./LICENSE), covering the code and docs in this repo. The plan document
78
- PDFs belong to their respective publishers and are not covered by it.
File without changes
File without changes
File without changes