Skip to content

Initial commit for Field Mapping POC using LLM - #10

Open
ishaanbhela-ai wants to merge 1 commit into
lending_poc/mainfrom
fieldMapping-poc
Open

Initial commit for Field Mapping POC using LLM#10
ishaanbhela-ai wants to merge 1 commit into
lending_poc/mainfrom
fieldMapping-poc

Conversation

@ishaanbhela-ai

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 no tests/ 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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants