Skip to content

fix: round-trip instruction request parts#5698

Open
he-yufeng wants to merge 1 commit into
pydantic:mainfrom
he-yufeng:fix/instruction-part-roundtrip
Open

fix: round-trip instruction request parts#5698
he-yufeng wants to merge 1 commit into
pydantic:mainfrom
he-yufeng:fix/instruction-part-roundtrip

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #5696.

Summary

  • add InstructionPart to the ModelRequestPart tagged union
  • add a regression test covering ModelMessagesTypeAdapter.dump_json() / validate_json() for request instruction parts

To verify

  • uv run python -c "from pydantic_ai.messages import ModelRequest, InstructionPart, ModelMessagesTypeAdapter; messages=[ModelRequest(parts=[InstructionPart(content='rule', dynamic=True)])]; serialized=ModelMessagesTypeAdapter.dump_json(messages); print(serialized.decode()); print(ModelMessagesTypeAdapter.validate_json(serialized))"
  • uv run pytest tests/test_messages.py::TestInstructionParts -q
  • uv run pytest tests/test_messages.py -q -k "InstructionParts or model_messages_type_adapter" -p no:cacheprovider
  • uv run ruff check pydantic_ai_slim\pydantic_ai\messages.py tests\test_messages.py
  • uv run python -m py_compile pydantic_ai_slim\pydantic_ai\messages.py tests\test_messages.py
  • git diff --check

I also ran the full tests/test_messages.py; it still has unrelated local Windows/environment failures in test_document_url_formats[csv] (mimetypes returns application/vnd.ms-excel) and test_binary_content_from_path (permission denied under C:\Users\He\AppData\Local\Temp\pytest-of-He).

The secondary BinaryImage demotion mentioned in the issue is not changed here.

@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) bug Report that something isn't working, or PR implementing a fix labels May 28, 2026
@he-yufeng he-yufeng force-pushed the fix/instruction-part-roundtrip branch 2 times, most recently from 7c41f02 to fc93d3c Compare May 28, 2026 12:43
@he-yufeng he-yufeng force-pushed the fix/instruction-part-roundtrip branch from fc93d3c to a4ce8f3 Compare May 28, 2026 12:56
@github-actions github-actions Bot added size: M Medium PR (101-500 weighted lines) and removed size: S Small PR (≤100 weighted lines) labels May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: M Medium PR (101-500 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[roundtrip-sweep] ModelRequest.parts: InstructionPart fails to deserialize after serialization

1 participant