feat(backend): add confidence score for each extracted field#66
Open
Godatcode wants to merge 2 commits into
Open
feat(backend): add confidence score for each extracted field#66Godatcode wants to merge 2 commits into
Godatcode wants to merge 2 commits into
Conversation
…m-core#60) Extend LLM extraction to return a confidence score (0-1) alongside each extracted value, enabling detection of uncertain extractions and supporting future human-review workflows. - Update build_prompt() to request JSON {value, confidence} format - Add "format": "json" to Ollama payload for reliable JSON output - Add parse_llm_response() with clamping and graceful fallback - Update add_response_to_json() to store {value, confidence} dicts - Log [WARNING] for fields with confidence < 0.5 - Update Fill.fill_form() to extract .value so PDF filling still works - Add get_confidence_report() convenience method - Add 17 unit tests covering parsing, clamping, fallback, and storage
Author
|
@juanalvv @vharkins @marcvergees — requesting your review on this PR. It adds confidence scores to the LLM extraction pipeline (issue #60). Happy to address any feedback! |
7 tasks
Author
|
@juanalvv @vharkins1 @marcvergees Could you review this when you get a chance? Happy to address any feedback. |
- Route low-confidence and JSON parse failure warnings to stderr instead of stdout for cleaner output separation - Add warning log when LLM response fails JSON parsing - Update tests to check stderr, add parse failure warning test
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.
Summary
Closes #60
{"value": "...", "confidence": 0.92}"format": "json") to request structured JSON responsesparse_llm_response()with clamping and graceful fallback for malformed responses[WARNING]for fields with confidence < 0.5Fill.fill_form()still passes plain strings to PDF fillingChanges
src/backend.py: Updatedbuild_prompt(),main_loop(),add_response_to_json(); addedparse_llm_response()andget_confidence_report()src/test/test_confidence.py: 17 unit tests covering JSON parsing, confidence clamping, fallback behavior, storage format, and warning outputTest plan
PYTHONPATH=src python -m pytest src/test/test_confidence.py -v[LOG] Resulting JSONshows{"value": ..., "confidence": ...}format[WARNING]appears for low-confidence fields