The Intelligent Form Agent is a powerful tool designed to process and understand digital forms (e.g., medical claims, financial reports). It automatically extracts information from both structured fields (like JSON data or labeled entries) and unstructured free-form text. The agent then utilizes this aggregated data to answer user questions, produce concise summaries, and generate holistic insights when analyzing multiple forms collectively.
The agent’s core capabilities are:
- Data Extraction: Reading and parsing form data, combining structured (JSON) and unstructured (Text) components.
- Question Answering (QA): Responding to user queries about a single form's content using both Extractive (Basic) and Abstractive/Reasoning (Advanced) methods.
- Summarization: Producing brief, narrative summaries highlighting the most important details of a form.
- Multi-Form Analysis: Aggregating and synthesizing information across multiple forms to provide holistic patient/subject reports.
Follow these steps to set up your environment and install the necessary dependencies.
- Python 3.7+
- Git
- (Optional but highly recommended) A virtual environment (using
venvorconda).
Clone the project from GitHub and navigate into the directory:
git clone https://github.com/arjunravi26/Intelligent-Form-Agent.git
cd Intelligent-Form-AgentInstall all required Python libraries listed in requirements.txt:
pip install -r requirements.txt-
Edit the
config.yamlfile to specify model names or paths. -
Create a
.envfile in the root directory and configure your Hugging Face API Token as an environment variable (required for model access):HF_TOKEN="<Your-HuggingFace-API-Key>"
- Ensure your sample form files (JSON and TXT pairs) are placed within the
/datadirectory (e.g.,data/claim/) or use the available sample data provided.
The agent is executed via the Python module system from the command line, using the main script and specific options.
Command Structure:
python -m main <OPTION> "<Your question>"| OPTION | Functionality | Question Required? |
|---|---|---|
qa |
Basic Extractive QA (Single Form) | YES |
advanced_qa |
Advanced Abstractive QA (Single Form) | YES |
summary |
Generates a Summary (Single Form) | NO |
analysis |
Holistic Multi-Form Report | NO |
The following examples simulate the agent's behavior across its core functions using the sample data.
Input:
python -m main qa "who is doctor?"Agent Output:
Output: Dr. David Chen
Input:
python -m main advanced_qa "who is doctor?"Agent Output:
Output: Answer: 'Dr. David Chen',
Reason: "The answer can be found in the 'provider_name' field of the claim details, which states: 'provider_name': 'Dr. David Chen (Pulmonology)'. This indicates that Dr. David Chen is the provider, and since he is mentioned as seeing the patient, it can be inferred that he is the doctor."
Input:
python -m main summaryAgent Output:
Output: “SummarizationOutput(summary_text='Patient Katelyn Whitaker (Policy: P49924-54) was seen today, 2025-07-17, by Dr. David Chen (Pulmonology). The main subjective complaint was a recurrent flare-up of their **Asthma** symptoms, which are generally well-managed. Assessment determined the necessity of a diagnostic procedure to confirm the severity: Spirometry (Lung Function Test) (CPT: 94010). The diagnosis code assigned is **J45.909**.')”
Input:
python -m main analysisAgent Output:
Output: “Print Holistic Report for Patient Katelyn Whitaker with Patient id PA-12345
Total Copay: 225.0
Total Allowed amount: 6102.94
Total Insurance paid: 5877.94
Provider names: {'Dr. Ava Sharma (Cardiology)', 'Dr. David Chen (Pulmonology)'}
Diagnosis count: defaultdict(<class 'int'>, {'Asthma': 1, 'Hypertension': 3})
No of times claim requested: 4”
(Note: This report aggregates all structured data available for Patient PA-12345 in the /data/claim directory.)
The system operates using a modular pipeline to process raw forms into structured knowledge for answering queries. The core differentiator is the use of Generative AI (LLMs) for abstractive reasoning and complex analysis.
-
Input Processing & Context Creation:
- Ingests form documents (JSON/TXT pairs).
- Combines both structured data (
claim_details.json) with unstructured data (claim_text_data.txt) into a unified context. - Cleans and formats data for optimal input to Large Language Models.
-
Question Answering Module - Basic (
qa):- Relies on a fine-tuned Extractive Model to precisely locate and return the answer from the context span.
-
Question Answering Module - Advanced (
advanced_qa):- Employs an Abstractive Model/LLM with a strict output format (JSON) to not only generate the
Answerbut also provide a logical, reasoned explanation (Reason) based on the input data.
- Employs an Abstractive Model/LLM with a strict output format (JSON) to not only generate the
-
Summarization Pipeline (
summary):- Utilizes a dedicated Summarization Model or an LLM prompted for summary generation using the full context.
-
Multi-Form Analysis (
analysis):- Iterates and aggregates information specifically from the structured data across all patient documents.
- Synthesizes key metrics (totals, counts, unique values) to produce a Holistic Report.
This modular architecture ensures that all core functions are powered by a unified data layer and leverages the specific strengths of various Gen AI and NLP models for distinct tasks (extraction, abstraction, and synthesis).
The Intelligent Form Agent moves beyond simple data capture, providing a robust pipeline for transforming raw form documents into actionable business intelligence. By integrating advanced extractive and abstractive models, the agent ensures that complex questions are answered with both precision and reasoning, and that insights across multiple claims are synthesized effectively.
We encourage you to clone the repository, follow the Setup Instructions, and experiment with the various modes (qa, advanced_qa, summary, and analysis).