Skip to content

Commit 14f4a53

Browse files
fix: query TaxBenefitModel by name before getting version (#69)
* feat: add structural reform support for economy and household calculations Adds run_structural_reform tool for the agent to run economy-wide structural reforms: - Agent calls POST /agent/run-structural-reform to trigger Modal - Modal applies simulation_modifier to reform simulation - Decile impacts calculated and stored - Agent polls until completion Also adds simulation_modifier support to household calculations: - Updated Modal household functions to use low-level Simulation API when modifier present - Added helper functions _calculate_uk/us_household_with_modifier - Updated _get_policy_data to include simulation_modifier - Agent can use policy_id with modifier in /household/calculate Fixes broken policyengine.outputs.inequality/poverty imports (module doesn't exist yet). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: query TaxBenefitModel by name before getting version TaxBenefitModelVersion doesn't have a name field - need to query TaxBenefitModel first, then get the version by model_id. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1f4ff97 commit 14f4a53

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/policyengine_api/api/agent_results.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
ReportStatus,
2626
Simulation,
2727
SimulationStatus,
28+
TaxBenefitModel,
2829
TaxBenefitModelVersion,
2930
Dataset,
3031
)
@@ -446,8 +447,17 @@ def run_structural_reform(
446447
)
447448
from sqlmodel import select
448449

450+
# First find the model by name, then get its latest version
451+
stmt = select(TaxBenefitModel).where(TaxBenefitModel.name == tax_benefit_model_name)
452+
model = session.exec(stmt).first()
453+
if not model:
454+
raise HTTPException(
455+
status_code=404,
456+
detail=f"No model found for {tax_benefit_model_name}",
457+
)
458+
449459
stmt = select(TaxBenefitModelVersion).where(
450-
TaxBenefitModelVersion.name == tax_benefit_model_name
460+
TaxBenefitModelVersion.model_id == model.id
451461
)
452462
model_version = session.exec(stmt).first()
453463
if not model_version:

0 commit comments

Comments
 (0)