Accept prose before the closing JSON fence in `PR Review Checks` answers

Merged
DS
22d ago
+57-15

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Why we make these changes

PR Review Checks fails on every review that DeepInfra serves: the job log reads The review answer was rejected: validation failed: json_invalid (run 43119781502). #13182 strips only a code fence that wraps the whole answer. A local run of the real prompt on DeepInfra gave the same answer shape 3 times out of 3: Markdown prose, then the JSON object in one json fence that ends the answer. With this PR, check_result validates the fenced block that ends the answer, whatever prose comes before it.

DeepInfra's JSON response mode (response_format) is deliberately not used: in a local probe it stopped every tool call, so the review read nothing.

New public surface

None. CI scripts only.

User-visible behavior

 answer: I read `a.py` and its callers.⏎⏎```json⏎{"outcome": "COMPLETE", ...}⏎```
-ValueError: The review answer was rejected: validation failed: json_invalid
+review COMPLETE with the fenced JSON object
  • Accepted: bare JSON, a fence around the whole answer, and prose (lists, paragraphs, code blocks) followed by a fence that ends the answer.
  • Still rejected with json_invalid: text after the closing fence, an unterminated fence, and prose before bare JSON.
  • The douwebot parser keeps its own fence rule; final_text and douwebot_opencode_result.py do not change.

Verification

pr-review-checks.yml runs default-branch scripts, so this PR's own PR Review Checks run still uses the old rule.

What changes for existing users

Nothing for library users; in CI, a PR Review Checks answer that ends with the fenced JSON object now passes validation.

PR decisions

2026-11-12 · PR Review Checks accepts prose before a closing fence · iter -

  • Decision: David chose option A: when a Markdown code fence ends the answer, check_result validates that fenced block even if prose comes before it; text after the fence, an unterminated fence and prose before bare JSON still fail. Do not touch final_text, douwebot_opencode_result.py or #13172. David authorizes merging over the douwebot gate via the merge queue once CI is green; never apply pr-review-checks:accepted
  • Why: A local repro with the real prompt on DeepInfra gave prose + one closing json fence in 3 of 3 runs; DeepInfra JSON mode stopped all tool use
  • Source: https://github.com/pydantic/pydantic-ai/actions/runs/43119781502
  • Session: 780cb84b-e583-4cde-b4fd-5145d534dbd2

2026-11-12 · pre-push review 1 of 3 at 26782319ff2d5856d8716ea138eaa22c52292ca9 · iter -

2026-11-12 · pre-push review 1 of 3 at 26782319ff2d5856d8716ea138eaa22c52292ca9 · iter -

  • Decision: three findings: (1) dismissed: the regex accepts a fenced block that ends the answer even when its opening line closed an earlier block; that is the chosen rule, and top-down fence pairing would instead reject prose with a stray fence line before a closing JSON fence; neither shape seen in real runs; (2) remediated: renamed the accepted-shapes test so its bare-JSON case fits; (3) remediated: rewrapped the workflows AGENTS.md sentence
  • Why: reviewed tree 95c2597d70f406c55098d6aaa4c9ebed232bfa15; scope 3dc712abf..26782319ff2d5856d8716ea138eaa22c52292ca9 full branch; light tier claude -p haiku from policy-base 3dc712abf; candidate and policy-base clean after review
  • Source: https://github.com/pydantic/pydantic-ai/tree/pr-review-checks-closing-fence
  • Session: 780cb84b-e583-4cde-b4fd-5145d534dbd2

2026-11-12 · exempt delta 26782319f..4f78323bc · iter -

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
  • PR title is fit for the release changelog.