PolicyPulse Development 2

From FDU-INS/Insurance-Skills · View interactive version

PolicyPulse Development 2 is an AI agent skill from the GitHub repository FDU-INS/Insurance-Skills. AI-powered synthetic population simulator with clean architecture, Python type safety, and professional dashboard design patterns

How to use this skill

Skill file

PolicyPulse Development

This skill guides AI agents in developing PolicyPulse, a professional analytical tool for stress-testing policies against synthetic populations using hybrid AI (LLM + Neural Network).

When to use

Activate this skill when:

Core Principles

1. Document-Driven Development

2. Clean Architecture (Modular Monolith)

Follow the defined module structure:

app.py              # Entry point, session management
ui_sections.py      # UI component rendering  
simulation.py       # Simulation orchestration
llm_client.py       # Gemini API wrapper
nn_model.py         # Neural network training/inference
population.py       # Synthetic citizen generation
stats.py            # Aggregation and statistics
data_models.py      # Dataclass definitions
utils.py            # Helper functions
config.py           # Environment loading
ml_data.py          # Training dataset management

Module Dependency Rules:

3. Python Type Safety

from dataclasses import dataclass
from typing import Literal

@dataclass
class Citizen:
    id: int
    age: int
    income_level: Literal["Low", "Middle", "High"]
    happiness: float
    
def calculate_average(citizens: list[Citizen]) -> float:
    return sum(c.happiness for c in citizens) / len(citizens)

4. Professional Dashboard Design

5. Streamlit-Specific Patterns

# Sidebar config
with st.sidebar:
    # Population, steps, mode, policy config
    pass

# Main content with tabs
tab1, tab2, tab3 = st.tabs(["Overview", "Demographics", "Individuals"])
with tab1:
    # Metrics cards, time-series charts
    pass

Implementation Guidelines

Data Models First

  1. Define dataclasses in data_models.py with full type annotations
  2. Include docstrings explaining purpose and constraints
  3. Use frozen=True for immutable data

Business Logic Isolation

  1. Keep simulation logic in simulation.py, population.py, nn_model.py
  2. No Streamlit imports in business logic modules
  3. Return structured data (dataclasses, DataFrames), not UI components

UI Components

  1. UI rendering functions in ui_sections.py
  2. Accept typed data structures as parameters
  3. Use Plotly for charts (st.plotly_chart(fig, use_container_width=True))
  4. Follow design system: spacing (8px base), typography (Inter font), colors

Error Handling

  1. Graceful degradation: LLM → NN → Rule-based fallback
  2. User-friendly error messages in UI
  3. Log technical details for debugging
  4. Never crash the app; show error state and recovery options

Testing Patterns

  1. Unit tests for business logic (population generation, stats calculations)
  2. Integration tests for simulation workflow
  3. Mock external dependencies (Gemini API)
  4. Validate type contracts with pytest

File Organization

policypulse/
├── .streamlit/
│   └── config.toml          # Streamlit configuration
├── data/
│   └── llm_training_samples.csv  # Persistent training data
├── models/
│   ├── citizen_reaction_model.joblib  # Trained NN
│   └── feature_scaler.joblib          # Feature normalization
├── src/                     # Source code modules
│   ├── app.py
│   ├── ui_sections.py
│   ├── simulation.py
│   ├── llm_client.py
│   ├── nn_model.py
│   ├── population.py
│   ├── stats.py
│   ├── data_models.py
│   ├── utils.py
│   ├── config.py
│   └── ml_data.py
├── tests/                   # Test files
├── requirements.txt         # Python dependencies
├── .env.example            # Template for API keys
├── .gitignore
└── README.md

Technology Stack Constraints

Anti-Patterns to Avoid

❌ Don't:

✅ Do:

Quick Reference

Adding a New Feature

  1. Verify it's in PRD.md
  2. Check DESIGN_DOC.md for UI specs
  3. Review TECH_STACK.md for implementation patterns
  4. Create/update data models if needed
  5. Implement business logic (pure Python)
  6. Add UI rendering (Streamlit components)
  7. Write tests
  8. Keep project runnable at each step

Code Review Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.