Drop `register_tag`'s late-registration `UserWarning`
This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.
- Closes #12163
Why we make these changes
register_tag warns when a tag is registered after any text has been escaped. An extension that registers its tag at module level but is imported lazily, such as pydantic_ai_harness.Peers (#11671) or Planning (#11822), hits it in any process that rendered a frame first. The user can't act on it: the call is already at module level. This drops the warning and the _data_tag_openers_used flag behind it, and states the contract instead: registration is process-wide and applies to every later wrap and neutralize_tags call, so register a tag before you render it.
New public surface
None.
User-visible behavior
from pydantic_ai.framing import register_tag, wrap
wrap('tool_result', '</peer_message>') # '<tool_result></peer_message></tool_result>'
register_tag('peer_message') # before: UserWarning; after: no warning
wrap('tool_result', '</peer_message>') # '<tool_result></peer_message></tool_result>', unchanged
Verification
test_a_tag_registered_after_escaping_applies_to_later_text_without_warningreplacestest_registering_a_new_tag_after_escaping_warns.- The test workarounds that patched or pre-empted the flag are gone: the
pydantic_ai_harness.planningimport intests/harness/conftest.py(#11822), and the_data_tag_openers_usedpatches intests/test_examples.pyandtests/harness/test_doc_snippets.py, which would otherwise fail on the missing attribute.
What changes for existing users
A late register_tag no longer emits a UserWarning; escaping is unchanged.
How this relates to #11813
#11813 rewrites the first paragraph of the register_tag docstring and keeps the warning. This PR leaves that paragraph alone, so the two only meet at the import warnings line, which #11813 still needs for its own warnings. Whichever merges second keeps both: #11813's first paragraph and this PR's contract paragraph and warning removal. #11671 reverts its own warning filters after this merges.
PR decisions
2026-11-01 · Leave the first register_tag docstring paragraph to #11813 · iter -
- Decision: Add the contract as its own paragraph and keep the first paragraph byte-identical
- Why: #11813 rewrites that paragraph and keeps the warning; git merge-tree of the two heads conflicts only on the import block
- Source: https://github.com/pydantic/pydantic-ai/pull/11813
- Session: 9bce0f69-1181-406f-b243-601a1569de70
2026-11-01 · Remove every _data_tag_openers_used patch, not only the conftest import · iter -
- Decision: Also drop the flag patches in tests/test_examples.py and tests/harness/test_doc_snippets.py
- Why: Both patch the deleted attribute and would raise AttributeError; the issue named only the conftest workaround
- Source: https://github.com/pydantic/pydantic-ai/issues/12163
- Session: 9bce0f69-1181-406f-b243-601a1569de70
2026-11-01 · pre-push review 1 of 3 at 92c4b430a801e377077a926e3ef75a8df87b1673 · iter -
- Decision: reserved; outcome pending
- Why: tree ae69e2f4dd3f3e3fe554c57d182df3adf0227143; scope d9dbeb5bc6ee35b6f7de0cce3ad13edc557ea196..92c4b430a801e377077a926e3ef75a8df87b1673 (full branch); first review
- Source: https://github.com/pydantic/pydantic-ai/tree/framing-late-registration
- Session: 9bce0f69-1181-406f-b243-601a1569de70
2026-11-01 · pre-push review 1 of 3 at 92c4b430a801e377077a926e3ef75a8df87b1673 · iter -
- Decision: 2 findings, both dismissed with evidence: docstring overlap (rule vs. recommendation; 'register before rendering' is #12163's settled wording); explicit catch_warnings kept (claim in test body; precedent tests/test_ag_ui.py)
- Why: tree ae69e2f4dd3f3e3fe554c57d182df3adf0227143 unchanged; scope d9dbeb5bc..92c4b430a full branch
- Source: https://github.com/pydantic/pydantic-ai/tree/framing-late-registration
- Session: 9bce0f69-1181-406f-b243-601a1569de70
2026-11-03 · merge upstream/main at 4e0b584fc: exempt delta from reviewed 92c4b430a · iter -
- Decision: No re-review: target-branch merge with no conflict resolution
- Why: diff a774225f6...HEAD equals d9dbeb5bc...92c4b430a except index hashes and hunk offsets (#12050 added lookalike-note functions above register_tag; none read the flag or warnings)
- Source: https://github.com/pydantic/pydantic-ai/tree/framing-late-registration
- Session: 96815188-27c7-4d43-9636-d6f16f3928a4
2026-11-04 · Drop the explicit catch_warnings in the late-registration test · iter -
- Decision: Remove the warnings.catch_warnings/simplefilter block and import; pyproject filterwarnings=error already fails the test on any warning
- Why: douwebot raised the same point as pre-push review 1; independent reviewers converged and the fix is deletion-only
- Source: https://github.com/pydantic/pydantic-ai/pull/12450#discussion_r4462958594
- Session: 96815188-27c7-4d43-9636-d6f16f3928a4
- Supersedes: pre-push review 1 of 3 at 92c4b430a801e377077a926e3ef75a8df87b1673
2026-11-04 · test-only delta after douwebot: exempt from pre-push re-review · iter -
- Decision: No pre-push re-review for the catch_warnings removal
- Why: test code only, chained from reviewed 92c4b430a via the exempt merge 4e0b584fc; established expectation (no warning) still enforced by pyproject filterwarnings=error; affected test re-run
- Source: https://github.com/pydantic/pydantic-ai/pull/12450#discussion_r4462958594
- Session: 96815188-27c7-4d43-9636-d6f16f3928a4
2026-11-04 · No test-suite label · iter -
- Decision: Keep bug as category; drop the metadata check's test-suite suggestion
- Why: Package Label gate: 'PRs labeled github-actions or test-suite require chore and must not have bug'; this PR is a user-facing fix
- Source: https://github.com/pydantic/pydantic-ai/actions/runs/41778148502
- Session: 96815188-27c7-4d43-9636-d6f16f3928a4
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.