Skip to content

feat(inspection): stage 2 response schema validation - #131

Merged
imran-siddique merged 1 commit into
mainfrom
worktree-agent-a62861066a3c21e79
Jun 6, 2026
Merged

feat(inspection): stage 2 response schema validation#131
imran-siddique merged 1 commit into
mainfrom
worktree-agent-a62861066a3c21e79

Conversation

@imran-siddique

Copy link
Copy Markdown
Member

Summary

  • Implements _stage2_schema_validation() in inspection/pipeline.py — validates JSON responses against output_schema in the catalog entry
  • Adds schema_validation_mode: Literal["redact", "strict", "log"] (default "redact") to CatalogEntry in catalog/loader.py
  • Wires Stage 2 into InspectionPipeline.run(): redact mode modifies response_bytes for downstream stages and sets InspectionResult.modified_response
  • Uses jsonschema (already a dependency via loader.py); surplus check is top-level only per spec

Closes #74

Test plan

  • test_skip_when_no_output_schema — no schema → stage skips
  • test_non_json_response_allows — non-JSON bytes pass through
  • test_valid_response_allows — conforming payload → allow, no modification
  • test_redact_mode_strips_surplus_fields — surplus fields removed, stripped_fields populated
  • test_pipeline_redact_mode_sets_modified_responseInspectionResult.modified_response is non-None
  • test_strict_mode_denies_on_surplus — deny with RESPONSE_SCHEMA_VIOLATION_STRICT
  • test_log_mode_allows_with_surplus_logged — allow, bytes unchanged, stripped_fields set
  • All 19 existing inspection tests still pass (33 total green)

🤖 Generated with Claude Code

Implements output_schema validation in the inspection pipeline. Supports
three per-entry modes — redact (default), strict, and log — driven by
schema_validation_mode on CatalogEntry. Redact mode strips surplus fields
and propagates modified_response to the caller; strict denies; log passes
through with audit metadata. Non-JSON responses and entries without
output_schema skip the stage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@imran-siddique
imran-siddique merged commit 9cb4851 into main Jun 6, 2026
7 checks passed
@imran-siddique
imran-siddique deleted the worktree-agent-a62861066a3c21e79 branch June 6, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[inspection] Stage 2 — response schema validation (redact/strict/log modes)

1 participant