PydanticFunctionsOutputParser()Parse an output as a pydantic object.
This parser is used to parse the output of a chat model that uses Google Vertex function format to invoke functions.
The parser extracts the function call invocation and matches them to the pydantic schema provided.
An exception will be raised if the function call does not match the provided schema.
Example:
message = AIMessage(
content="This is a test message",
additional_kwargs={
"function_call": {
"name": "cookie",
"arguments": json.dumps({"name": "value", "age": 10}),
}
},
)
chat_generation = ChatGeneration(message=message)
class Cookie(BaseModel):
name: str
age: int
class Dog(BaseModel):
species: str
# Full output
parser = PydanticOutputFunctionsParser(
pydantic_schema={"cookie": Cookie, "dog": Dog}
)
result = parser.parse_result([chat_generation])