Skip to content

Commit 7f16cb6

Browse files
hua7450claude
andcommitted
Add defined_for scoping guidance for person-level program variables
Person-level variables like reimbursement rates should use defined_for with the person-level eligibility variable, not just the state code, to avoid unnecessary computation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ce5ed62 commit 7f16cb6

File tree

1 file changed

+23
-0
lines changed
  • skills/technical-patterns/policyengine-variable-patterns-skill

1 file changed

+23
-0
lines changed

skills/technical-patterns/policyengine-variable-patterns-skill/SKILL.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ class some_variable(Variable):
207207
reference = "https://example.gov/rules.pdf#page=10" # USE THIS
208208
```
209209

210+
### Scoping `defined_for` to the Right Level
211+
212+
`defined_for` controls which entities run the formula. Use the most specific scope that fits:
213+
214+
```python
215+
# ❌ TOO BROAD — calculates rates for all RI residents (adults, ineligible children)
216+
class ri_ccap_licensed_center_rate(Variable):
217+
entity = Person
218+
defined_for = StateCode.RI
219+
220+
# ✅ CORRECT — only calculates rates for children eligible for CCAP
221+
class ri_ccap_licensed_center_rate(Variable):
222+
entity = Person
223+
defined_for = "ri_ccap_eligible_child"
224+
```
225+
226+
**Guidelines:**
227+
- **SPMUnit-level benefit variables** → `defined_for = "state_program_eligible"` (the main eligibility variable)
228+
- **Person-level variables within a program** (rates, per-child amounts) → `defined_for = "state_program_eligible_child"` or the person-level eligibility variable
229+
- **Eligibility check variables themselves** → `defined_for = StateCode.XX` (they determine eligibility, so they can't depend on it)
230+
231+
This avoids unnecessary computation and makes the variable's scope clear from its definition.
232+
210233
**Reference format:**
211234
```python
212235
# Single reference:

0 commit comments

Comments
 (0)