Add results.json schema validation and source tracking#237
Draft
PavelMakarchuk wants to merge 2 commits intoPolicyEngine:mainfrom
Draft
Add results.json schema validation and source tracking#237PavelMakarchuk wants to merge 2 commits intoPolicyEngine:mainfrom
PavelMakarchuk wants to merge 2 commits intoPolicyEngine:mainfrom
Conversation
New `policyengine.results` module with two pieces: - `schema.py`: Pydantic models (ResultsJson, ValueEntry, TableEntry, ChartEntry) that validate results.json at generation time. Catches missing source_line/source_url, row/column mismatches in tables, and vague alt text on charts before they reach the blog build step. - `tracking.py`: `tracked_value()` helper that captures the caller's line number via `inspect` and builds the source_url automatically. Eliminates repetitive inspect.currentframe() boilerplate in analysis scripts. These support the blog post content pipeline where every number in a published post links back to the exact line of analysis code that produced it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use model_dump(mode="json") instead of json.loads(model_dump_json()) to avoid unnecessary serialize→parse→serialize round-trip - Create parent directories automatically so callers don't need to mkdir first - Add trailing newline to output file - Add test for nested directory creation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Adds a
policyengine.resultsmodule with two small pieces that support the blog post content pipeline:schema.py): Pydantic models that validate results.json at generation timetracking.py): Helper that auto-captures line numbers for traceabilityWhat it does
Schema validation
Catches errors at generation time:
source_lineorsource_urlon any valueSource tracking
Why
Every number in a PolicyEngine blog post should link to the exact line of code that produced it. This module ensures the results.json contract is valid before it reaches the resolve-posts build step.
Test plan
🤖 Generated with Claude Code