Skip to content

[Python SDK] Trouble with cross agent pydantic (un)marshalling #1034

Description

@pocesar

Describe the bug

Sometimes complex pydantic models in reasoners and skills and multiple arguments can cause the inputs paramters to become a simple dict, forcing pydantic model coercion.

And a side note: sometimes the parameters being put inside TYPE_CHECK blocks also builds properly but crash during deployment.

Steps to reproduce

Using parameters like:

  • item: PydanticModel1 | PydanticModel2 | None = None
  • items: list[PydanticModel1] | list[PydanticModel2] | None = None
  • maybe_empty_sequence: Sequence[PydanticModel1 | None] = []

In most cases, those fall through and crash during runtime. Nested JSON under the input can cause this as well.

Using the new RUFF 0.16 UP rules might have to do with this since it prefers using list[model] | None instead of Optional[List[model]] on newer python versions

Expected behavior

Inputs and outputs always recursively validate if they are a pydantic model, inputs are ensured to be an instance of the model / dataclass. Outputs survives roundrip losslessly

Screenshots / Logs

Environment

  • Control plane version: 0.1.127
  • SDK version (if applicable): 0.1.130
  • Deployment environment (local, docker, kubernetes, etc.):

Additional context

Another side note: ruff allows to place decorators (flake8-type-checking) in runtime-evaluated-decorators and exempt-modules. Not sure if this can be set at the AF SDK level that will be inherited or it needs to be set manually for every project

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions