Skip to content

fix(anthropic): harden structured JSON parsing - #5

Open
lzhs1995 wants to merge 3 commits into
feat/dormant-gate-b-20260730from
fix/kiro-structured-json-hardening-20260730
Open

fix(anthropic): harden structured JSON parsing#5
lzhs1995 wants to merge 3 commits into
feat/dormant-gate-b-20260730from
fix/kiro-structured-json-hardening-20260730

Conversation

@lzhs1995

Copy link
Copy Markdown
Owner

Summary

  • accept one whole-response JSON fence across LF/CRLF, unlabelled, and case-insensitive json forms
  • split empty structured output into kiro_structured_empty_output
  • log privacy-preserving diagnostics without raw response content
  • keep prose, unsupported labels, malformed fences, and trailing content fail-closed

Validation

  • local linux/amd64 release build: pass
  • focused structured_json_is_strict_and_canonical: 1 passed, 0 failed
  • git diff --check: pass

Deployment boundary

Train A only. This PR does not enable Gate B flags, change RPM, modify credentials/proxies, or authorize shadow/canary/enforce. Any new kiro.rs digest invalidates the prior R2 evidence and requires a fresh R2 anchor.

Copilot AI review requested due to automatic review settings July 30, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Anthropic structured JSON output handling by making fenced JSON extraction more robust (LF/CRLF, unlabeled fences, case-insensitive json), introducing a dedicated error kind for empty structured output, and adding privacy-preserving diagnostics that avoid logging raw response content.

Changes:

  • Broaden accepted whole-response JSON fences (unlabeled and json label, case-insensitive; LF/CRLF supported) while still failing closed on prose, unsupported labels, malformed fences, or trailing content.
  • Split “empty structured output” into a distinct kiro_structured_empty_output error kind.
  • Add warn-level structured diagnostics (lengths, fence classification, first non-whitespace classification, per-process salted digest, optional parse position) without logging raw content, plus tests for the new parsing rules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants