skills/technical-patterns/policyengine-code-organization-skill/SKILL.md
Code organization patterns for PolicyEngine - variable naming conventions, folder structure, file organization
npx skillsauth add policyengine/policyengine-claude policyengine-code-organizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Patterns for organizing PolicyEngine code - naming conventions, folder structure, and file organization.
The variable prefix is defined in sources/working_references.md.
Look for this section:
## Official Program Name
**Federal Program**: [Federal program name]
**State's Official Name**: [State's official name]
**Abbreviation**: [Abbreviation]
**Source**: [Legal citation]
**Variable Prefix**: `[state]_[abbreviation]`
Use this prefix for all variable and parameter names.
# Pattern: {state}_{program}
az_liheap # Arizona LIHEAP
ca_calfresh # California CalFresh (SNAP)
ny_heap # New York HEAP (LIHEAP)
ma_snap # Massachusetts SNAP (uses federal name)
# Sub-variables: {state}_{program}_{component}
az_liheap_eligible
az_liheap_income_eligible
az_liheap_benefit_amount
# Pattern: just {program}
snap
liheap
wic
# Sub-variables: {program}_{component}
snap_eligible
snap_gross_income
liheap_eligible
Use these standard suffixes with your variable prefix:
{prefix}_eligible # Final eligibility (combines all checks)
{prefix}_income_eligible # Income eligibility
{prefix}_resource_eligible # Resource/asset eligibility
{prefix}_activity_eligible # Work/activity requirement eligibility
{prefix}_categorical_eligible # Categorical eligibility
{prefix}_demographic_eligible # Age, household composition eligibility
{prefix}_immigration_eligible # Immigration status eligibility
{prefix} # Final benefit amount
{prefix}_maximum_benefit # Maximum possible benefit
{prefix}_countable_income # Income after deductions
{prefix}_countable_earned_income
{prefix}_countable_unearned_income
{prefix}_gross_income # Total income before deductions
{prefix}_earned_income_disregard
{prefix}_work_expense_deduction
{prefix}_dependent_care_deduction
{prefix}_standard_deduction
{prefix}_income_limit
{prefix}_resource_limit
{prefix}_payment_standard
{prefix}_need_standard # Use state's terminology
Use the terminology from sources/working_references.md.
States use different terms for the same concepts:
| Concept | Possible Terms | Example |
|---------|---------------|---------|
| Benefit amount | Payment Standard, Need Standard, Grant Amount | {prefix}_need_standard |
| Income threshold | Gross Income Limit, GMI, Countable Income Limit | {prefix}_gmi_limit |
| Earnings deduction | Earned Income Disregard, Work Expense Deduction | {prefix}_earned_income_disregard |
Match the exact terms from the documentation.
{prefix}.py) stays at the program folder rootincome/ - Income calculations, limits, deductionseligibility/ - Eligibility checksresources/ - Asset/resource calculationsdeductions/ - Deductions and disregardsEach program is different. Before organizing, look at similar programs in the codebase:
ls policyengine_us/variables/gov/states/{state}/{agency}/
policyengine_us/variables/gov/states/{state}/{agency}/{program}/
├── {prefix}.py # Final benefit (at root)
├── {prefix}_eligible.py
├── {prefix}_income_eligible.py
├── {prefix}_maximum_benefit.py
└── {prefix}_countable_income.py
policyengine_us/variables/gov/states/{state}/{agency}/{program}/
├── {prefix}.py # Final benefit (at root)
├── eligibility/
│ ├── {prefix}_eligible.py
│ ├── {prefix}_income_eligible.py
│ └── {prefix}_resource_eligible.py
└── income/
├── {prefix}_countable_income.py
└── {prefix}_gross_income.py
policyengine_us/variables/gov/states/{state}/{agency}/{program}/
├── {prefix}.py # Final benefit (at root)
├── eligibility/
│ ├── {prefix}_eligible.py
│ ├── {prefix}_income_eligible.py
│ ├── {prefix}_resource_eligible.py
│ └── {prefix}_demographic_eligible.py
├── income/
│ ├── {prefix}_countable_income.py
│ ├── {prefix}_countable_earned_income.py
│ └── {prefix}_gross_income.py
└── deductions/
├── {prefix}_earned_income_disregard.py
└── {prefix}_work_expense_deduction.py
policyengine_us/tests/policy/baseline/gov/states/{state}/{agency}/{program}/
├── {prefix}.yaml
├── {prefix}_eligible.yaml
├── {prefix}_income_eligible.yaml
└── integration.yaml # Always named integration.yaml
Parameter folders follow similar principles to variable folders — group by function.
Each subfolder should contain parameters that serve the same function. Don't use a folder as a catch-all.
# ❌ BAD — eligibility/ contains rate dimension boundaries that aren't eligibility criteria
ccap/
├── eligibility/
│ ├── income_limit.yaml # ✅ Eligibility
│ ├── child_age_threshold.yaml # ✅ Eligibility
│ ├── center_infant_max_months.yaml # ❌ Rate table age group boundary
│ ├── preschool_max_years.yaml # ❌ Rate table age group boundary
│ └── time_category.yaml # ❌ Authorization concept
└── rates/
# ✅ GOOD — each folder contains parameters that match its purpose
ccap/
├── age_groups/ # Age group boundaries for rate lookups
│ ├── center_infant_max_months.yaml
│ └── preschool_max_years.yaml
├── eligibility/ # Actual eligibility criteria
│ ├── income_limit.yaml
│ └── child_age_threshold.yaml
├── rates/
└── time_category.yaml # At root — doesn't fit neatly in a subfolder
The key question: "Is this parameter an eligibility rule, a rate-table dimension boundary, a benefit calculation input, or something else?" Put it in the folder that matches its function.
# ❌ WRONG - Using federal name when state has official name
ca_tanf_eligible # California calls it CalWORKs
# ✅ CORRECT - Using state's official name
ca_calworks_eligible
# ❌ WRONG - Inconsistent naming
az_liheap_benefit
az_liheap_eligible_status # Should be az_liheap_eligible
# ✅ CORRECT - Consistent pattern
az_liheap
az_liheap_eligible
# ❌ WRONG - Prefixed integration test
az_liheap_integration.yaml
# ✅ CORRECT - Standard integration test name
integration.yaml
# ❌ WRONG - Descriptive test names
test_low_income_family.yaml
# ✅ CORRECT - Variable-based test names
az_liheap.yaml
az_liheap_eligible.yaml
tools
ONLY use this skill when users explicitly ask about the PolicyEngine Python package installation, REST API endpoints, API authentication, rate limits, or policyengine.py client library. DO NOT use for household benefit/tax calculations — ALWAYS use policyengine-us or policyengine-uk instead. This skill is about the API/client tooling itself, not about calculating benefits or taxes.
development
ALWAYS USE THIS SKILL for PolicyEngine microsimulation, population-level analysis, winners/losers calculations. Triggers: microsimulation, share who would lose/gain, policy impact, national average, weighted analysis, cost, revenue impact, budgetary, estimate the cost, federal revenues, tax revenue, budget score, how much would it cost, how much would the policy cost, total cost of, aggregate impact, cost to the government, revenue loss, fiscal impact, poverty impact, child poverty, deep poverty, poverty rate, poverty reduction, how many people lifted out of poverty, SPM poverty, distributional impact, state tax, state-level, California, New York, UBI, universal basic income, flat tax, standard deduction, winners and losers, winners, losers, inequality, Gini, decile, SALT, marginal tax rate, effective tax rate. NOT for single-household calculations like "what would my benefit be" - use policyengine-us or policyengine-uk for those. Use this skill's code pattern; explore codebase for parameter paths if needed.
development
PolicyEngine API v2 - Next-generation microservices architecture with monorepo structure
development
ALWAYS LOAD THIS SKILL before setting up any Python environment or installing packages. Defines the standard: uv, Python 3.13, uv pip install, .venv at project root. Triggers: "set up python", "install python", "create a venv", "virtual environment", "pip install", "install packages", "uv pip", "uv venv", "python version", "VIRTUAL_ENV", "venv conflict", "which python", "activate", "deactivate", "run the script", "run with uv", "uv run", "pyproject.toml", "install dependencies", "install requirements", "install the package", "editable install", "pip install -e", "latest package", "latest version", "current version", "newest version".