Skip to content

Python: serialize durabletask options response format#6819

Open
VectorPeak wants to merge 3 commits into
microsoft:mainfrom
VectorPeak:codex-durabletask-response-format-options
Open

Python: serialize durabletask options response format#6819
VectorPeak wants to merge 3 commits into
microsoft:mainfrom
VectorPeak:codex-durabletask-response-format-options

Conversation

@VectorPeak

@VectorPeak VectorPeak commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

RunRequest.to_dict() already serializes the top-level response_format, but options["response_format"] can still contain a raw Pydantic model class.

That means a durable request like this cannot cross the JSON transport boundary:

RunRequest(
    message="Test",
    correlation_id="corr",
    options={"response_format": MyModel},
)

Calling json.dumps(request.to_dict()) raises because the model class is not JSON serializable. The affected path is:

DurableAIAgent.run(..., options={"response_format": Model})
  -> RunRequest(...)
  -> RunRequest.to_dict()
  -> durable JSON transport

Description & Review Guide

  • What are the major changes?

    • Serialize options["response_format"] using the same module/qualname marker already used for top-level response_format.
    • Deserialize that marker back to the Pydantic model class in RunRequest.from_dict() when it can be resolved.
    • Drop unresolved options-level durable response format markers so they do not block fallback to the top-level response_format.
    • Add regression tests for the JSON boundary and unresolved marker fallback behavior.
  • What is the impact of these changes?

    • Durable RunRequest payloads with options["response_format"] can cross the JSON boundary.
    • Other option keys are preserved unchanged.
    • The top-level response_format behavior is unchanged.
  • What do you want reviewers to focus on?

    • The helper intentionally handles only the known durable response_format option rather than recursively transforming arbitrary options.

Related Issue

Fixes #6821

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) - a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 30, 2026 05:21
@moonbox3 moonbox3 added the python Usage: [Issues, PRs], Target: Python label Jun 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes durable JSON transport serialization for RunRequest.options["response_format"] by converting Pydantic model classes to the existing {module, qualname} marker format during to_dict(), and restoring them during from_dict(). This ensures durable requests can safely cross a JSON boundary without embedding non-serializable Python class objects.

Changes:

  • Add _serialize_options() to convert options["response_format"] (when it’s a Pydantic model class) into the durable marker dict during RunRequest.to_dict().
  • Add _deserialize_options() to restore options["response_format"] marker dicts back into the Pydantic model class during RunRequest.from_dict().
  • Add a regression test that round-trips to_dict() -> json.dumps/loads -> from_dict() for options["response_format"].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
python/packages/durabletask/agent_framework_durabletask/_models.py Serializes/deserializes the durable options["response_format"] value to cross JSON boundaries.
python/packages/durabletask/tests/test_models.py Adds regression coverage for JSON round-tripping options["response_format"].

Comment thread python/packages/durabletask/agent_framework_durabletask/_models.py Outdated
@VectorPeak VectorPeak marked this pull request as ready for review June 30, 2026 05:25
@VectorPeak VectorPeak requested a review from a team as a code owner June 30, 2026 05:25
@VectorPeak VectorPeak force-pushed the codex-durabletask-response-format-options branch from 1466fe4 to 7e52b8f Compare June 30, 2026 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Python durabletask RunRequest options response_format is not JSON serializable

3 participants