An interactive framework for experimenting with and evaluating open-source large language models (LLMs) for insurance-related tasks. This application provides a user-friendly interface for prompt engineering, text generation, model comparison, and benchmark creation.
21
stars
7
commits
Python
primary language
Apr 21, 2026
updated
An open-source prompt engineering and evaluation framework for insurance domain applications, leveraging the power of Large Language Models (LLMs) to transform insurance workflows.
The Insurance LLM Framework provides a comprehensive suite of tools for insurance professionals to leverage open-source Large Language Models (LLMs) for various domain-specific tasks. By combining prompt engineering, model management, and evaluation capabilities, the framework enables insurance companies to harness the power of AI for improving operational efficiency and customer experience.
The framework is specifically designed for insurance-related tasks such as:
The framework offers a comprehensive set of features designed to make LLMs accessible and effective for insurance professionals:
# Clone the repository
git clone https://github.com/yourusername/insurance-llm-framework.git
cd insurance-llm-framework
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Optional: Install GPU dependencies if you have a compatible GPU
pip install torch==2.1.2+cu118 -f https://download.pytorch.org/whl/torch_stable.html
# Build the Docker image
docker build -t insurance-llm-framework .
# Run the container
docker run -p 8501:8501 -v $(pwd)/data:/app/data insurance-llm-framework
Create a .env file in the root directory with the following variables:
# HuggingFace token for accessing gated models (required for some models)
HF_TOKEN=your_huggingface_token
# Application settings
APP_PORT=8501
APP_HOST=0.0.0.0
# Model cache directory (optional)
TRANSFORMERS_CACHE=./models/cache
# Logging level (optional)
LOG_LEVEL=INFO
# Basic usage
python run.py
# With custom port and host
python run.py --port 8502 --host 127.0.0.1
# With debug logging
LOG_LEVEL=DEBUG python run.py
The framework components can be imported and used programmatically:
from insurance_llm.models import ModelLoader
from insurance_llm.prompts import PromptLibrary
from insurance_llm.evaluation import EvaluationMetrics
# Load a model
model_loader = ModelLoader()
model, tokenizer = model_loader.load_model("phi-2", quantization="8bit")
# Get a prompt template
prompt_library = PromptLibrary()
template = prompt_library.get_template("policy_summary")
# Generate text
prompt = template.format(policy_text="Your policy text here...")
inference = ModelInference(model, tokenizer)
result = inference.generate(prompt, max_length=512)
# Evaluate the result
metrics = EvaluationMetrics()
score = metrics.evaluate(result, reference_text="Reference summary")
print(f"ROUGE-L score: {score['rouge-l']}")
insurance-llm-framework/
├── app.py # Main Streamlit application
├── run.py # Application startup script
├── requirements.txt # Project dependencies
├── Dockerfile # Docker configuration
├── .env # Environment variables (create this)
├── config/ # Configuration files
│ ├── models.yaml # Model configuration
│ ├── prompts.yaml # Prompt configuration
│ └── evaluation.yaml # Evaluation configuration
├── data/ # Sample insurance data
│ ├── policies/ # Sample policy documents
│ ├── claims/ # Sample claim documents
│ └── communications/ # Sample customer communications
├── models/ # Model integration
│ ├── model_loader.py # Classes for loading models
│ ├── inference.py # Classes for model inference
│ └── cache/ # Model cache directory
├── prompts/ # Prompt engineering components
│ ├── templates/ # Reusable prompt templates
│ ├── strategies.py # Prompt design strategies
│ └── library.py # Prompt library manager
├── evaluation/ # Evaluation components
│ ├── metrics.py # Automated evaluation metrics
│ ├── human_eval.py # Human evaluation protocols
│ ├── benchmarks.py # Benchmark datasets and tests
│ ├── evaluations/ # Evaluation results
│ └── benchmarks/ # Benchmark datasets
├── ui/ # UI components
│ ├── pages/ # Different pages of the app
│ ├── components/ # Reusable UI components
│ └── utils.py # UI utility functions
├── utils/ # Utility functions
│ ├── logging.py # Logging configuration
│ ├── file_utils.py # File handling utilities
│ └── text_processing.py # Text processing utilities
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── fixtures/ # Test fixtures
└── docs/ # Detailed documentation
├── use_cases.md # Insurance use cases
├── prompt_engineering.md # Prompt engineering guide
├── evaluation.md # Evaluation guide
├── api_reference.md # API documentation
└── examples/ # Example notebooks and scripts
ModelManagement
├── ModelConfig
├── ModelLoader
├── PipelineFactory
└── ModelInference
PromptEngineering
├── PromptTemplate
├── PromptLibrary
└── PromptStrategy
├── ZeroShotStrategy
├── FewShotStrategy
└── ChainOfThoughtStrategy
Evaluation
├── EvaluationMetric
│ ├── ROUGEMetric
│ ├── BLEUMetric
│ ├── BERTScoreMetric
│ └── CustomMetric
├── MetricsManager
└── HumanEvaluationManager
Benchmarking
├── Benchmark
├── BenchmarkExample
├── BenchmarkManager
└── BenchmarkResult
UI
├── ModelSelectionPage
├── PromptEngineeringPage
├── EvaluationPage
├── BenchmarksPage
├── ModelComparisonPage
└── SettingsPage
Utilities
├── TorchUtils
├── SessionState
├── DataLoader
├── ThreadingUtils
├── SystemInfo
└── EnvironmentSetup
The framework supports a variety of open-source LLMs with different capabilities and resource requirements:
| Model | Parameters | Context Length | Best For | CPU Friendly |
|---|---|---|---|---|
| LLaMA-2 7B | 7 billion | 4096 tokens | General text generation | No |
| LLaMA-2 13B | 13 billion | 4096 tokens | Higher quality generation | No |
| LLaMA-2 7B Chat | 7 billion | 4096 tokens | Conversational applications | No |
| LLaMA-2 13B Chat | 13 billion | 4096 tokens | Higher quality conversations | No |
| Mistral 7B | 7 billion | 8192 tokens | Long context generation | No |
| Mistral 7B Instruct | 7 billion | 8192 tokens | Instruction following | No |
| Falcon 7B | 7 billion | 2048 tokens | Efficient generation | No |
| Falcon 7B Instruct | 7 billion | 2048 tokens | Instruction following | No |
| Phi-2 | 2.7 billion | 2048 tokens | CPU-friendly generation | Yes |
| Phi-1.5 | 1.3 billion | 2048 tokens | Lightweight inference | Yes |
| TinyLLaMA 1.1B | 1.1 billion | 2048 tokens | Fast CPU inference | Yes |
For GPU environments:
For CPU environments:
The framework supports adding custom models by extending the ModelConfig class:
# Add a custom model to the configuration
ModelConfig.MODEL_REPOS["custom-model"] = "path/to/custom/model"
ModelConfig.MODEL_DETAILS["custom-model"] = {
"description": "Custom model description",
"parameters": "X billion",
"context_length": "Y tokens",
"suitable_for": "Specific tasks",
"cpu_friendly": False
}
The framework includes extensive optimizations for both CPU and GPU environments:
| Model | GPU (RTX 3090) | CPU (8 cores) | CPU (4 cores) |
|---|---|---|---|
| LLaMA-2 13B | 15 tokens/sec | 0.5 tokens/sec | 0.2 tokens/sec |
| LLaMA-2 7B | 30 tokens/sec | 1 token/sec | 0.5 tokens/sec |
| Mistral 7B | 25 tokens/sec | 0.8 tokens/sec | 0.4 tokens/sec |
| Phi-2 | 60 tokens/sec | 3 tokens/sec | 1.5 tokens/sec |
| TinyLLaMA 1.1B | 100 tokens/sec | 5 tokens/sec | 2.5 tokens/sec |
The framework provides comprehensive prompt engineering capabilities for insurance domain tasks:
Prompt templates are structured with variables that can be substituted at runtime:
Template: policy_summary
Task: Summarize the key points of an insurance policy
Variables: policy_text
Strategy: zero_shot
I need to understand the key points of this insurance policy. Please provide a concise summary that includes:
1. Coverage limits
2. Major exclusions
3. Deductible amounts
4. Important conditions
Policy text:
{policy_text}
Summary:
The framework supports multiple prompting strategies:
The framework includes templates for common insurance tasks:
Custom templates can be created through the UI or programmatically:
from prompts.library import PromptTemplate, PromptLibrary
# Create a new template
template = PromptTemplate(
name="custom_template",
template="This is a template with {variable1} and {variable2}",
task_type="custom_task",
description="A custom template for specific tasks",
variables=["variable1", "variable2"],
strategy_type="zero_shot"
)
# Add to library
library = PromptLibrary()
library.add_template(template)
The framework provides comprehensive evaluation capabilities for assessing the quality of generated outputs:
Custom metrics can be added by extending the EvaluationMetric class:
from evaluation.metrics import EvaluationMetric, EvaluationResult
class InsuranceAccuracyMetric(EvaluationMetric):
def __init__(self):
super().__init__(
name="insurance_accuracy",
description="Measures accuracy of insurance-specific information",
max_score=1.0
)
def evaluate(self, generated_text, reference_text, context=None):
# Implement custom evaluation logic
score = calculate_accuracy(generated_text, reference_text)
return EvaluationResult(
metric_name=self.name,
score=score,
max_score=self.max_score,
details={"analysis": "Custom analysis details"}
)
The framework includes a comprehensive benchmarking system for comparing model performance:
Each benchmark consists of:
Benchmarks can be run through the UI or programmatically:
from evaluation.benchmarks import BenchmarkManager
# Get benchmark manager
benchmark_manager = BenchmarkManager()
# Run benchmark
results = benchmark_manager.run_benchmark(
benchmark_name="policy_summary",
model=model,
tokenizer=tokenizer,
inference_engine=inference_engine
)
# Analyze results
average_score = results.get_average_score()
per_example_scores = results.get_per_example_scores()
The framework provides tools for comparing different models on the same benchmarks:
The framework is designed to be extensible in various ways:
ModelConfig.MODEL_REPOS with the new model repositoryModelConfig.MODEL_DETAILSModelLoader.load_modelprompts/templates/PromptLibraryPromptStrategyEvaluationMetricevaluate methodMetricsManagerevaluation/benchmarks/BenchmarkBenchmarkManagerui/pages/render methodProblem: "CUDA out of memory" error
Problem: Model loading is extremely slow on CPU
Problem: "Token not found" error when loading gated models
Problem: Generation times out
Problem: Poor quality outputs
Problem: Memory usage grows with each generation
TorchUtils.clear_gpu_memory()Problem: Streamlit crashes during model loading
Problem: UI becomes unresponsive during generation
The framework uses Python's logging module for debugging:
# Run with debug logging
LOG_LEVEL=DEBUG python run.py
# Check log files
cat app.log # Application logs
cat run.log # Startup logs
Contributions to the Insurance LLM Framework are welcome! Here's how you can contribute:
# Clone the repository
git clone https://github.com/yourusername/insurance-llm-framework.git
cd insurance-llm-framework
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
git checkout -b feature/amazing-feature)pytest)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
7 commits
Python
100.0%
An interactive framework for experimenting with and evaluating open-source large language models (LLMs) for insurance-related tasks. This application provides a user-friendly interface for prompt engineering, text generation, model comparison, and benchmark creation.
21
stars
7
commits
Python
primary language
Apr 21, 2026
updated
An open-source prompt engineering and evaluation framework for insurance domain applications, leveraging the power of Large Language Models (LLMs) to transform insurance workflows.
The Insurance LLM Framework provides a comprehensive suite of tools for insurance professionals to leverage open-source Large Language Models (LLMs) for various domain-specific tasks. By combining prompt engineering, model management, and evaluation capabilities, the framework enables insurance companies to harness the power of AI for improving operational efficiency and customer experience.
The framework is specifically designed for insurance-related tasks such as:
The framework offers a comprehensive set of features designed to make LLMs accessible and effective for insurance professionals:
# Clone the repository
git clone https://github.com/yourusername/insurance-llm-framework.git
cd insurance-llm-framework
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Optional: Install GPU dependencies if you have a compatible GPU
pip install torch==2.1.2+cu118 -f https://download.pytorch.org/whl/torch_stable.html
# Build the Docker image
docker build -t insurance-llm-framework .
# Run the container
docker run -p 8501:8501 -v $(pwd)/data:/app/data insurance-llm-framework
Create a .env file in the root directory with the following variables:
# HuggingFace token for accessing gated models (required for some models)
HF_TOKEN=your_huggingface_token
# Application settings
APP_PORT=8501
APP_HOST=0.0.0.0
# Model cache directory (optional)
TRANSFORMERS_CACHE=./models/cache
# Logging level (optional)
LOG_LEVEL=INFO
# Basic usage
python run.py
# With custom port and host
python run.py --port 8502 --host 127.0.0.1
# With debug logging
LOG_LEVEL=DEBUG python run.py
The framework components can be imported and used programmatically:
from insurance_llm.models import ModelLoader
from insurance_llm.prompts import PromptLibrary
from insurance_llm.evaluation import EvaluationMetrics
# Load a model
model_loader = ModelLoader()
model, tokenizer = model_loader.load_model("phi-2", quantization="8bit")
# Get a prompt template
prompt_library = PromptLibrary()
template = prompt_library.get_template("policy_summary")
# Generate text
prompt = template.format(policy_text="Your policy text here...")
inference = ModelInference(model, tokenizer)
result = inference.generate(prompt, max_length=512)
# Evaluate the result
metrics = EvaluationMetrics()
score = metrics.evaluate(result, reference_text="Reference summary")
print(f"ROUGE-L score: {score['rouge-l']}")
insurance-llm-framework/
├── app.py # Main Streamlit application
├── run.py # Application startup script
├── requirements.txt # Project dependencies
├── Dockerfile # Docker configuration
├── .env # Environment variables (create this)
├── config/ # Configuration files
│ ├── models.yaml # Model configuration
│ ├── prompts.yaml # Prompt configuration
│ └── evaluation.yaml # Evaluation configuration
├── data/ # Sample insurance data
│ ├── policies/ # Sample policy documents
│ ├── claims/ # Sample claim documents
│ └── communications/ # Sample customer communications
├── models/ # Model integration
│ ├── model_loader.py # Classes for loading models
│ ├── inference.py # Classes for model inference
│ └── cache/ # Model cache directory
├── prompts/ # Prompt engineering components
│ ├── templates/ # Reusable prompt templates
│ ├── strategies.py # Prompt design strategies
│ └── library.py # Prompt library manager
├── evaluation/ # Evaluation components
│ ├── metrics.py # Automated evaluation metrics
│ ├── human_eval.py # Human evaluation protocols
│ ├── benchmarks.py # Benchmark datasets and tests
│ ├── evaluations/ # Evaluation results
│ └── benchmarks/ # Benchmark datasets
├── ui/ # UI components
│ ├── pages/ # Different pages of the app
│ ├── components/ # Reusable UI components
│ └── utils.py # UI utility functions
├── utils/ # Utility functions
│ ├── logging.py # Logging configuration
│ ├── file_utils.py # File handling utilities
│ └── text_processing.py # Text processing utilities
├── tests/ # Test suite
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── fixtures/ # Test fixtures
└── docs/ # Detailed documentation
├── use_cases.md # Insurance use cases
├── prompt_engineering.md # Prompt engineering guide
├── evaluation.md # Evaluation guide
├── api_reference.md # API documentation
└── examples/ # Example notebooks and scripts
ModelManagement
├── ModelConfig
├── ModelLoader
├── PipelineFactory
└── ModelInference
PromptEngineering
├── PromptTemplate
├── PromptLibrary
└── PromptStrategy
├── ZeroShotStrategy
├── FewShotStrategy
└── ChainOfThoughtStrategy
Evaluation
├── EvaluationMetric
│ ├── ROUGEMetric
│ ├── BLEUMetric
│ ├── BERTScoreMetric
│ └── CustomMetric
├── MetricsManager
└── HumanEvaluationManager
Benchmarking
├── Benchmark
├── BenchmarkExample
├── BenchmarkManager
└── BenchmarkResult
UI
├── ModelSelectionPage
├── PromptEngineeringPage
├── EvaluationPage
├── BenchmarksPage
├── ModelComparisonPage
└── SettingsPage
Utilities
├── TorchUtils
├── SessionState
├── DataLoader
├── ThreadingUtils
├── SystemInfo
└── EnvironmentSetup
The framework supports a variety of open-source LLMs with different capabilities and resource requirements:
| Model | Parameters | Context Length | Best For | CPU Friendly |
|---|---|---|---|---|
| LLaMA-2 7B | 7 billion | 4096 tokens | General text generation | No |
| LLaMA-2 13B | 13 billion | 4096 tokens | Higher quality generation | No |
| LLaMA-2 7B Chat | 7 billion | 4096 tokens | Conversational applications | No |
| LLaMA-2 13B Chat | 13 billion | 4096 tokens | Higher quality conversations | No |
| Mistral 7B | 7 billion | 8192 tokens | Long context generation | No |
| Mistral 7B Instruct | 7 billion | 8192 tokens | Instruction following | No |
| Falcon 7B | 7 billion | 2048 tokens | Efficient generation | No |
| Falcon 7B Instruct | 7 billion | 2048 tokens | Instruction following | No |
| Phi-2 | 2.7 billion | 2048 tokens | CPU-friendly generation | Yes |
| Phi-1.5 | 1.3 billion | 2048 tokens | Lightweight inference | Yes |
| TinyLLaMA 1.1B | 1.1 billion | 2048 tokens | Fast CPU inference | Yes |
For GPU environments:
For CPU environments:
The framework supports adding custom models by extending the ModelConfig class:
# Add a custom model to the configuration
ModelConfig.MODEL_REPOS["custom-model"] = "path/to/custom/model"
ModelConfig.MODEL_DETAILS["custom-model"] = {
"description": "Custom model description",
"parameters": "X billion",
"context_length": "Y tokens",
"suitable_for": "Specific tasks",
"cpu_friendly": False
}
The framework includes extensive optimizations for both CPU and GPU environments:
| Model | GPU (RTX 3090) | CPU (8 cores) | CPU (4 cores) |
|---|---|---|---|
| LLaMA-2 13B | 15 tokens/sec | 0.5 tokens/sec | 0.2 tokens/sec |
| LLaMA-2 7B | 30 tokens/sec | 1 token/sec | 0.5 tokens/sec |
| Mistral 7B | 25 tokens/sec | 0.8 tokens/sec | 0.4 tokens/sec |
| Phi-2 | 60 tokens/sec | 3 tokens/sec | 1.5 tokens/sec |
| TinyLLaMA 1.1B | 100 tokens/sec | 5 tokens/sec | 2.5 tokens/sec |
The framework provides comprehensive prompt engineering capabilities for insurance domain tasks:
Prompt templates are structured with variables that can be substituted at runtime:
Template: policy_summary
Task: Summarize the key points of an insurance policy
Variables: policy_text
Strategy: zero_shot
I need to understand the key points of this insurance policy. Please provide a concise summary that includes:
1. Coverage limits
2. Major exclusions
3. Deductible amounts
4. Important conditions
Policy text:
{policy_text}
Summary:
The framework supports multiple prompting strategies:
The framework includes templates for common insurance tasks:
Custom templates can be created through the UI or programmatically:
from prompts.library import PromptTemplate, PromptLibrary
# Create a new template
template = PromptTemplate(
name="custom_template",
template="This is a template with {variable1} and {variable2}",
task_type="custom_task",
description="A custom template for specific tasks",
variables=["variable1", "variable2"],
strategy_type="zero_shot"
)
# Add to library
library = PromptLibrary()
library.add_template(template)
The framework provides comprehensive evaluation capabilities for assessing the quality of generated outputs:
Custom metrics can be added by extending the EvaluationMetric class:
from evaluation.metrics import EvaluationMetric, EvaluationResult
class InsuranceAccuracyMetric(EvaluationMetric):
def __init__(self):
super().__init__(
name="insurance_accuracy",
description="Measures accuracy of insurance-specific information",
max_score=1.0
)
def evaluate(self, generated_text, reference_text, context=None):
# Implement custom evaluation logic
score = calculate_accuracy(generated_text, reference_text)
return EvaluationResult(
metric_name=self.name,
score=score,
max_score=self.max_score,
details={"analysis": "Custom analysis details"}
)
The framework includes a comprehensive benchmarking system for comparing model performance:
Each benchmark consists of:
Benchmarks can be run through the UI or programmatically:
from evaluation.benchmarks import BenchmarkManager
# Get benchmark manager
benchmark_manager = BenchmarkManager()
# Run benchmark
results = benchmark_manager.run_benchmark(
benchmark_name="policy_summary",
model=model,
tokenizer=tokenizer,
inference_engine=inference_engine
)
# Analyze results
average_score = results.get_average_score()
per_example_scores = results.get_per_example_scores()
The framework provides tools for comparing different models on the same benchmarks:
The framework is designed to be extensible in various ways:
ModelConfig.MODEL_REPOS with the new model repositoryModelConfig.MODEL_DETAILSModelLoader.load_modelprompts/templates/PromptLibraryPromptStrategyEvaluationMetricevaluate methodMetricsManagerevaluation/benchmarks/BenchmarkBenchmarkManagerui/pages/render methodProblem: "CUDA out of memory" error
Problem: Model loading is extremely slow on CPU
Problem: "Token not found" error when loading gated models
Problem: Generation times out
Problem: Poor quality outputs
Problem: Memory usage grows with each generation
TorchUtils.clear_gpu_memory()Problem: Streamlit crashes during model loading
Problem: UI becomes unresponsive during generation
The framework uses Python's logging module for debugging:
# Run with debug logging
LOG_LEVEL=DEBUG python run.py
# Check log files
cat app.log # Application logs
cat run.log # Startup logs
Contributions to the Insurance LLM Framework are welcome! Here's how you can contribute:
# Clone the repository
git clone https://github.com/yourusername/insurance-llm-framework.git
cd insurance-llm-framework
# Create a virtual environment
python -m venv .venv
source .venv/bin/activate
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
git checkout -b feature/amazing-feature)pytest)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
7 commits
Python
100.0%