AGENT SKILL

postgres-schema-expert

Instructions for managing the PostgreSQL schema, writing SQL queries, and maintaining data integrity for the insurance analytics project.

License 许可
Apache-2.0
最近更新
2026-07-12
Stars
★ 82
Forks
18

01 前言 Front Matter

name
postgres-schema-expert
description
Instructions for managing the PostgreSQL schema, writing SQL queries, and maintaining data integrity for the insurance analytics project.

03 SKILL.md 正文

PostgreSQL Schema Expert Skill

This skill covers the database layer of the insurance analytics project: the insurance schema, table definitions, indexes, SQL patterns, and data-integrity rules.

Schema overview

All tables live in the insurance schema inside the insurdb database.

insurance
├── member      – one row per enrolled health-plan member
├── provider    – one row per healthcare provider
└── claim       – one row per insurance claim (child of member + provider)

The DDL lives in src/sql/ddl_create_tables.sql and is applied with:

# DATABASE_URL uses the SQLAlchemy format (postgresql+psycopg2://...).
# psql requires a driver-free URL — strip the +psycopg2 prefix:
PSQL_URL="${DATABASE_URL/+psycopg2/}"
psql "$PSQL_URL" -f src/sql/ddl_create_tables.sql
# or use the Makefile shortcut (handles the URL conversion for you):
make db-init

Table definitions

insurance.member

Column Type Notes
member_id BIGSERIAL PRIMARY KEY Auto-incrementing surrogate key
person_id BIGINT External identifier
dob DATE Date of birth — used to derive age in Python
gender VARCHAR(10) 'male' / 'female' / 'U' — Kaggle datasets map the source sex column to gender; 'U' is the default when gender is absent
region VARCHAR(50) Geographic region (e.g. 'Northeast')
effective_date DATE Coverage start date
termination_date DATE Coverage end date (NULL = still active)

insurance.provider

Column Type Notes
provider_id BIGSERIAL PRIMARY KEY Auto-incrementing surrogate key
specialty VARCHAR(80) Medical specialty (e.g. 'Cardiology')
in_network BOOLEAN TRUE = in-network, FALSE = out-of-network
region VARCHAR(50) Geographic region of the provider

insurance.claim

Column Type Notes
claim_id BIGSERIAL PRIMARY KEY Auto-incrementing surrogate key
member_id BIGINT FK → member Required — every claim belongs to a member
provider_id BIGINT FK → provider Required — every claim belongs to a provider
service_date DATE Date the service was rendered
diagnosis_code VARCHAR(8) ICD-10 code (e.g. 'Z00.00')
procedure_code VARCHAR(8) CPT code (e.g. '99213')
billed_amount NUMERIC(12,2) Amount the provider billed
allowed_amount NUMERIC(12,2) Maximum amount the plan will pay
paid_amount NUMERIC(12,2) Amount actually paid by the plan
place_of_service VARCHAR(20) E.g. 'Office', 'Hospital'

Indexes

-- Speeds up joins from claim → member
CREATE INDEX IF NOT EXISTS idx_claim_member      ON insurance.claim(member_id);
-- Speeds up date-range queries on claims
CREATE INDEX IF NOT EXISTS idx_claim_service_date ON insurance.claim(service_date);

Add new indexes only when a slow query is identified. Over-indexing slows down INSERT/UPDATE.

Common SQL query patterns

Monthly paid totals by region

SELECT
    DATE_TRUNC('month', c.service_date) AS month,
    m.region,
    COUNT(*)                            AS claim_count,
    SUM(c.paid_amount)                  AS paid_total
FROM insurance.claim c
JOIN insurance.member m ON c.member_id = m.member_id
GROUP BY 1, 2
ORDER BY 1, 2;

In-network vs out-of-network comparison

SELECT
    p.in_network,
    COUNT(*)           AS claims,
    AVG(c.paid_amount) AS avg_paid,
    SUM(c.paid_amount) AS total_paid
FROM insurance.claim c
JOIN insurance.provider p ON c.provider_id = p.provider_id
GROUP BY p.in_network;

Claims for currently active members only

SELECT c.*
FROM insurance.claim c
JOIN insurance.member m ON c.member_id = m.member_id
WHERE m.termination_date IS NULL
   OR m.termination_date > CURRENT_DATE;

Top 10 providers by paid amount

SELECT
    c.provider_id,
    p.specialty,
    SUM(c.paid_amount) AS paid_total
FROM insurance.claim c
JOIN insurance.provider p ON c.provider_id = p.provider_id
GROUP BY 1, 2
ORDER BY paid_total DESC
LIMIT 10;

Resetting and re-initialising the database

# Drop and recreate the schema, then re-apply DDL
make db-reset

# Equivalent raw SQL (strip the +psycopg2 driver prefix for psql compatibility)
PSQL_URL="${DATABASE_URL/+psycopg2/}"
psql "$PSQL_URL" -c "DROP SCHEMA IF EXISTS insurance CASCADE;"
psql "$PSQL_URL" -c "CREATE SCHEMA insurance;"
psql "$PSQL_URL" -f src/sql/ddl_create_tables.sql

Load behaviour and idempotency

src/load.py uses a truncate-then-load strategy so repeated runs are safe:

-- Runs inside a single transaction
TRUNCATE insurance.claim, insurance.provider, insurance.member CASCADE;

This means every make kaggle-load call replaces all data. Do not run it on a production database with live data unless you intend to replace everything.

Data-integrity rules

  1. Foreign keys – Every claim must reference an existing member and provider. PostgreSQL enforces this automatically.
  2. Numeric scale – NUMERIC(12,2) stores up to 10 digits before the decimal and exactly 2 after. Never store amounts as FLOAT — floating-point rounding causes accounting errors.
  3. Date columns – Always store dates as DATE, never as VARCHAR. This enables range comparisons and DATE_TRUNC without casting.
  4. Schema isolation – All objects live in the insurance schema, not public. This keeps the database clean if other schemas are added later.

Environment variable

The application connects using the DATABASE_URL environment variable:

DATABASE_URL=postgresql+psycopg2://postgres:postgres@localhost:5432/insurdb

The psql CLI accepts a slightly different format (no driver prefix):

psql "postgresql://postgres:postgres@localhost:5432/insurdb"

04 同仓库更多 Skills

FDU-INS
FDU-INS/Insurance-Skills

로인장 (Roinjiang)

Activates when the user needs legal advice, contract review, insurance law consultation, startup legal support, or any legal/regulatory matter. She is a top-tier in-house lawyer with absolute loyalty to the CEO, specializing in insurance law, financial consumer protection, privacy, contracts, labor law, family law, civil and criminal matters.

★ 82
FDU-INS
FDU-INS/Insurance-Skills

zocdoc-doctor-finder

Use when a user needs to find a doctor, dentist, specialist, therapist, or healthcare provider — especially when they mention insurance, in-network, availability, location, appointments, or booking. Also use for browsing provider reviews, comparing doctors by specialty, or checking if a provider takes their insurance.

★ 82
FDU-INS
FDU-INS/Insurance-Skills

zenmux-context

Answers any question about ZenMux by reading the latest official documentation. Use this skill whenever the user asks about ZenMux product features, API usage, configuration, integration, pricing, models, providers, routing, fallback, streaming, multimodal, structured output, tool calling, reasoning, prompt caching, image generation, video generation, web search, long context, observability, logs, cost tracking, usage analytics, insurance, subscription, pay-as-you-go, invoices, best practices for tools like Claude Code, Cursor, Cline, CodeX, Gemini CLI, opencode, Cherry Studio, Obsidian, Sider, Open-WebUI, Dify, Neovate, GitHub Copilot, OpenClaw, CC-Switch, Immersive Translate, Studio Chat, architecture, benchmarks, FAQ, contact, privacy, terms of service, compliance, or any other ZenMux-related topic. Also trigger when the user writes in Chinese about ZenMux: 文档, 使用指南, 快速开始, API 参考, 最佳实践, 模型路由, 供应商路由, 订阅, 按量计费, 可观测性, 帮助, 常见问题, 接入指南, 配置. Trigger on phrases like "how to use ZenMux", "ZenMux docs", "ZenMux API", "ZenMux integration", "ZenMux 怎么用", "ZenMux 接入", "ZenMux 配置". Even if the user doesn't say "ZenMux" explicitly but asks about LLM API aggregation, model routing, provider fallback in a context where ZenMux is the project being worked on, this skill should activate.

★ 82
FDU-INS
FDU-INS/Insurance-Skills

workers-comp-guide

Guide workers compensation compliance and claims management. TRIGGERS - Use when user needs help with workers-comp-guide related tasks.

★ 82
FDU-INS
FDU-INS/Insurance-Skills

weekly-kpi-report

Generate McKinsey-style board presentation PPTs from weekly auto insurance data. Automatically calculates 16+ KPIs, creates executive-level slides with actionable insights, and supports week-over-week comparisons. Use when user uploads insurance cost data (Excel/CSV) and requests board report, weekly presentation, executive briefing, or mentions keywords like 董事会汇报, 周报PPT, 经营分析演示, McKinsey-style reports.

★ 82
FDU-INS
FDU-INS/Insurance-Skills

wealth-advisory

Wealth management and financial planning for HNW and UHNW clients. Activate when the user mentions wealth management, financial planning, retirement, estate planning, tax planning, GRAT, IDGT, trust, asset allocation, withdrawal rate, Monte Carlo simulation, goals-based investing, tax-loss harvesting, Roth conversion, insurance, annuity, mortgage strategy, concentrated stock, family office, direct indexing, 529 plan, charitable giving, donor-advised fund, private foundation, or asks about personal finance strategy, inheritance, long-term financial planning, or UHNW advisory.

★ 82