Pydantic refactor#151
Closed
Cubix33 wants to merge 2 commits into
Closed
Conversation
This was referenced Mar 2, 2026
Author
|
Closing for now to reduce load on maintainers. Will reopen after further discussion or during GSOC. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #148
🚀 Description
This PR fundamentally overhauls the core extraction logic in
src/llm.pyby integrating Pydantic and Ollama's native JSON Structured Outputs.Previously,
main_loopiterated sequentially through every field, making N API calls to the LLM and relying on fragile string parsing (replace('"', "")) to format the output. This was slow, prone to hallucinations, and broke easily if the LLM wrapped its answer in unexpected formatting.This update introduces a single-pass, strictly typed architecture:
create_model) based on the target PDF fields.formatAPI payload parameter.This reduces extraction time by drastically cutting API calls and guarantees 100% reliable data structures.
🛠️ Changes Made
pydantic>=2.0.0torequirements.txt.src/llm.py:add_response_to_jsonandhandle_plural_valuesstring parsers.build_schema()to map complex PDF field names to valid Python identifiers.map_schema_to_json()to reconstruct the raw target fields forfiller.py.main_loop()to execute a single, schema-enforced API call.🧪 How to Test
pip install -r requirements.txtto install Pydantic.make exec.[LOG] Extracting all fields using Pydantic structured output...and complete the entire PDF mapping in a single, fast operation.✅ Checklist
filler.pyexpectations.