You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: skills/technical-patterns/policyengine-variable-patterns-skill/SKILL.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -207,6 +207,29 @@ class some_variable(Variable):
207
207
reference = "https://example.gov/rules.pdf#page=10" # USE THIS
208
208
```
209
209
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.
0 commit comments