Feat/Batch Multi Form Fill with Canonical Extraction and Evidence Attribution#158
Open
Acuspeedster wants to merge 4 commits intofireform-core:mainfrom
Open
Feat/Batch Multi Form Fill with Canonical Extraction and Evidence Attribution#158Acuspeedster wants to merge 4 commits intofireform-core:mainfrom
Acuspeedster wants to merge 4 commits intofireform-core:mainfrom
Conversation
…emplate tests with detailed assertions and mock setups
…uce API calls and improve performance
…tribution
The core promise of FireForm is 'report once, file everywhere'. This commit
delivers that promise at the API level.
## What this adds
### POST /forms/fill/batch
One incident transcript -> fill N agency PDFs in a single request.
Extraction complexity: O(T*F) LLM calls -> O(1 + T) LLM calls
(T templates, F fields each; e.g. 5 agencies x 10 fields = 50 -> 6 calls)
Pipeline:
1. Single canonical LLM extraction pass (all incident data, one call)
2. Concurrent template-mapping passes via asyncio.gather() (T fast calls)
3. Concurrent PDF fills via loop.run_in_executor() (no event-loop blocking)
4. Per-template FormSubmission records + one BatchSubmission audit record
5. Partial failure tolerance: some PDFs can fail without aborting others
### GET /forms/batches/{id}
Lightweight status check: per-template output paths, success/failure counts.
### GET /forms/batches/{id}/audit [legal compliance endpoint]
Full canonical extraction for chain-of-custody verification. Every extracted
field carries the verbatim transcript quote used as evidence, allowing
supervisors and legal teams to trace every value in every filed form back
to a specific statement in the original incident recording.
## New files
- src/extractor.py IncidentExtractor class (canonical + mapping)
- api/routes/batch.py Three new endpoints
- api/schemas/batch.py BatchFill, TemplateResult, EvidenceField, ...
- tests/test_batch.py 24 tests (all passing)
## Modified files
- api/db/models.py BatchSubmission SQLModel table
- api/db/repositories.py create_batch / get_batch CRUD
- api/main.py Register batch router; add OpenAPI metadata
- src/filler.py Add fill_form_with_data() (name-based field fill)
- tests/conftest.py Import FillJob + BatchSubmission for test DB
38 tests pass.
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 #155
Closes #156
Closes #157
Summary
This PR operationalizes FireForm’s "report once, file everywhere" promise at the API level.
It introduces:
From an architectural standpoint, this PR should be considered high priority, as it resolves a core scalability and compliance limitation affecting FireForm’s primary multi-agency use case.
Architectural Redesign
Separation of Concerns
Previously:
Now:
IncidentExtractor
New
extractor.pyintroducesIncidentExtractor.Pass 1:
Pass 2:
asyncio.gatherComplexity Improvement
Previous:
T × F LLM calls
New:
1 + T LLM calls
Example:
5 templates × 10 fields = 50 calls
Now = 6 calls
Concurrency
New Endpoints
POST
/forms/fill/batchGET
/forms/batches/{id}GET
/forms/batches/{id}/auditPartial Failure Handling
Callers never lose successful fills due to unrelated template error.
Database Changes
New
BatchSubmissiontable:Repository additions:
Testing
24 new tests
Total: 38 passing
Coverage includes:
Operational Significance
This PR:
Given that multi-agency filing is the primary use case FireForm is designed to solve, resolving this redundancy and audit gap is foundational for production readiness.