Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Python: Pydantic error when attempting to use Literal type for tool parameter #2891

Description

@dtkettler

I have a class with a function I want to use as a tool in an Agent Framework agent.

def search_flows(self, category: Literal["Data", ...], issue: str) -> str:

(There are more options for the Literal, I just don't want to list them all. They're all strings though.)

But when I try to run the agent, I get the following error:

Exception has occurred: PydanticUserError
search_flows_input is not fully defined; you should define Data, then call search_flows_input.model_rebuild().

The 'Data' there seems to be a reference to the first Literal value? It's just a string though, I don't know how I would define it any more than it already is.

I have determined that it's definitely the Literal that's the issue here though because if I change the function to:

def search_flows(self, category: str, issue: str) -> str:

Then it does run. Of course, I can't guarantee that category is in a fixed set of values this way, which is the reason I wanted to use a Literal here.

Is this a bug or is there some other method I should be using to restrict values like this?

Metadata

Metadata

Assignees

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: Python

Type

Fields

No fields configured for Bug.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions