Initial commit for Field Mapping POC using LLM - #10
Open
ishaanbhela-ai wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces an initial “Field Mapping POC” module that maps unstructured OCR text into an arbitrary JSON schema using a local Ollama LLM, with post-processing to normalize/repair JSON and flag model-added fields.
Changes:
- Adds the core mapping pipeline (
FieldMapper, prompt builder, Ollama client, response parsing/normalization). - Adds sample schemas and OCR-like text fixtures to demo the mapping behavior.
- Adds basic docs and dependency pinning for running the POC locally.
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| lending-poc/modules/field_mapping_poc/schemas/examples/salary_slip.json | Example flat target schema for extraction. |
| lending-poc/modules/field_mapping_poc/schemas/examples/identity_card.json | Example nested target schema for extraction. |
| lending-poc/modules/field_mapping_poc/samples/sample_salary_slip.txt | Clean salary slip sample text. |
| lending-poc/modules/field_mapping_poc/samples/sample_salary_slip_noisy.txt | Noisy/OCR-corrupted salary slip sample text. |
| lending-poc/modules/field_mapping_poc/samples/sample_ocr_text.txt | OCR-style sample text for demo usage. |
| lending-poc/modules/field_mapping_poc/run_samples.py | Convenience script to run the pipeline on local samples. |
| lending-poc/modules/field_mapping_poc/requirements.txt | Adds Ollama Python dependency for the POC. |
| lending-poc/modules/field_mapping_poc/README.md | POC documentation, usage, and design notes. |
| lending-poc/modules/field_mapping_poc/main.py | CLI demo entrypoint for running a schema/text mapping. |
| lending-poc/modules/field_mapping_poc/core/response_parser.py | JSON parsing/repair and schema reconciliation logic. |
| lending-poc/modules/field_mapping_poc/core/prompt_builder.py | System/user prompt construction from schema + text. |
| lending-poc/modules/field_mapping_poc/core/ollama_client.py | Ollama wrapper with JSON-mode call and retries. |
| lending-poc/modules/field_mapping_poc/core/mapper.py | Orchestration entrypoint for mapping fields end-to-end. |
| lending-poc/modules/field_mapping_poc/core/init.py | Package marker for core. |
| lending-poc/modules/field_mapping_poc/config.py | Centralizes environment-tunable configuration and tagging constants. |
Suppressed comments (1)
lending-poc/modules/field_mapping_poc/README.md:53
- The README claims offline tests can be run from
tests/, but notests/directory exists in this module in the current commit. Either add the tests or adjust this section to avoid broken instructions.
## Run the offline tests (no Ollama required)
```bash
python tests/test_response_parser.py
# or, with pytest installed:
python -m pytest tests/ -v
</details>
---
💡 <a href="/joshsoftware/LegalAI/new/lending_poc/main?filename=.github/skills/code-review/SKILL.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Add a `code-review` agent skill</a> or configure MCP servers for context-aware, tailored reviews. <a href="https://docs.github.com/en/copilot/how-tos/use-copilot-agents/request-a-code-review/use-code-review#mcp-servers-and-agent-skills" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Learn more in the docs.</a>
Comment on lines
+28
to
+39
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser(description="LegalAI Field Mapping POC") | ||
| parser.add_argument("--schema", type=Path, | ||
| help="Path to a JSON file describing the target schema") | ||
| parser.add_argument("--text", type=Path, | ||
| help="Path to a text file containing raw OCR output") | ||
|
|
||
| args = parser.parse_args() | ||
| if args.schema is None or args.text is None: | ||
| raise ValueError("Both --schema and --text paths must be provided.") | ||
|
|
||
| return args |
Comment on lines
+40
to
+46
| # Run the clean sample | ||
| clean_text = "test_inputs/sample_salary_slip.txt" | ||
| run_sample(schema_file, clean_text) | ||
|
|
||
| # Run the noisy OCR sample | ||
| noisy_text = "test_inputs/sample_salary_slip_noisy.txt" | ||
| run_sample(schema_file, noisy_text) |
Comment on lines
+115
to
+120
| if isinstance(value, dict): | ||
| # Nested extra object: recurse with an empty schema so every | ||
| # leaf inside it also gets flagged as llm_added. | ||
| result[key] = reconcile_with_schema({}, value) | ||
| else: | ||
| result[key] = _wrap_extra(value) |
Comment on lines
+11
to
+27
| ``` | ||
| legalai_field_mapping_poc/ | ||
| ├── config.py # model name, ollama host, retries, flagging keys | ||
| ├── main.py # CLI demo entry point | ||
| ├── core/ | ||
| │ ├── ollama_client.py # thin wrapper around the ollama lib + retries | ||
| │ ├── prompt_builder.py # builds the system/user prompt from schema + text | ||
| │ ├── response_parser.py # JSON repair + schema reconciliation | ||
| │ └── mapper.py # FieldMapper — orchestrates the three above | ||
| ├── schemas/examples/ | ||
| │ ├── salary_slip.json # flat schema example | ||
| │ └── identity_card.json # nested schema example (address object) | ||
| ├── samples/ | ||
| │ └── sample_ocr_text.txt # messy OCR-style salary slip for the demo | ||
| └── tests/ | ||
| └── test_response_parser.py # offline tests, no Ollama needed | ||
| ``` |
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.
No description provided.