Warn on unknown keys beside values: in parameter YAML#506
Merged
Conversation
A parameter node carrying `values:` plus an unknown sibling key (most
damagingly an `uprating:` block placed outside `metadata:`) had that key
silently dropped, freezing indexed parameters at their last explicit value.
Reinstate allowed-key validation in the parameter loader as a
ParameterKeyWarning that names the file, the offending key, and the fix
("move `uprating` under `metadata:`"). Emitted as a warning now, intended to
become a hard error in a future major release so country packages can sweep
their trees first. `reference` and `unit` remain recognized for backward
compatibility.
Fixes #505
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Author
|
Fable review: the enforcement gap was real (allowed_keys accepted but never checked since the OpenFisca port); warn-mode per #505's rollout plan, with the legacy reference/unit carve-out and bracket common-keys expansion preventing false positives — validated against the full policyengine-us tree (96 warnings, all true positives including a silently-dropped refrence typo, zero false). 595 tests + 39 country-template green. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #505.
Problem
The parameter loader accepted
allowed_keysin_validate_parameterbut never enforced it, so an unknown key placed besidevalues:was silently discarded. The most damaging instance is anuprating:block written as a sibling ofvalues:instead of undermetadata:: the file looks like it uprates, loads cleanly, and passes CI, while the parameter freezes at its last explicit value (documented across ~25 policyengine-us files in PolicyEngine/policyengine-us#8905).Change
Reinstates unknown-key validation as a warning (not an error), per the issue's warn-in-minor / error-in-major rollout:
ParameterKeyWarning(inpolicyengine_core.warnings)._validate_parameternow flags any key outside the node's allowed set, naming the file, the offending key, and the fix (Moveupratingundermetadata:.).allowed_keysis already passed: top-level parameters, breakdown children, scale nodes, scale-bracket component leaves, index files, and value-at-instant nodes.description/metadata/documentationkeys in addition to their tax components, so bracket-levelmetadata(used to route uprating, see Scale parameter thresholds don't support uprating #390) does not warn.referenceandunitremain recognized as backward-compatible legacy keys (LEGACY_COMPAT_KEYS) so existing correctly- and legacy-authored files do not emit noise.Real-world validation
Loading the full policyengine-us parameter tree with this change emits 96 warnings, each a real latent bug: 95 misplaced
upratingblocks (matching the ~103 nodes in policyengine-us#8905) plus onerefrencetypo that was being silently dropped. Correctly-placedreference/unit/uprating(undermetadata:) produce zero warnings.Tests
tests/core/parameter_validation/test_unknown_keys.py(9 tests): a siblinguprating:triggers the warning naming file/key/fix; a metadata-nesteduprating:does not; scale-level, bracket-level, and bracket-component-leaf cases covered; a fully valid parameter emits nothing.unknown_key_beside_values.yaml(warns) anduprating_under_metadata.yaml(does not).Checks run
uv run pytest tests -m "not smoke"→ 595 passed, 1 skipped, 1 xfailed.policyengine-core teston the bundled country template → 39 passed, no key warnings.ruff format(clean) andruff check(passed).-m smokesuite (requires network / GitHub microdata token).🤖 Generated with Claude Code