Drop `register_tag`'s late-registration `UserWarning`

Merged
DS
21d ago
+9-39

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

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>&lt;/peer_message></tool_result>', unchanged

Verification

  • test_a_tag_registered_after_escaping_applies_to_later_text_without_warning replaces test_registering_a_new_tag_after_escaping_warns.
  • The test workarounds that patched or pre-empted the flag are gone: the pydantic_ai_harness.planning import in tests/harness/conftest.py (#11822), and the _data_tag_openers_used patches in tests/test_examples.py and tests/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 -

2026-11-01 · pre-push review 1 of 3 at 92c4b430a801e377077a926e3ef75a8df87b1673 · iter -

2026-11-03 · merge upstream/main at 4e0b584fc: exempt delta from reviewed 92c4b430a · iter -

2026-11-04 · Drop the explicit catch_warnings in the late-registration test · iter -

2026-11-04 · test-only delta after douwebot: exempt from pre-push re-review · iter -

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.