Python: Bug: [PYTHON] Chat history serializing error
Describe the bug I have a user message and an azure open ai assistant message in the chat history. I'm trying to serialize the chat history object to a json string so I can save it. When I try to use the serialize function in the chat history class, I get the error below.
"Error: Unable to serialize ChatHistory to JSON: Error serializing to JSON: TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer'"
To Reproduce Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behavior Get a json string
Screenshots If applicable, add screenshots to help explain your problem.
Platform
- OS: Windows
- IDE: VS Code
- Language: Python
- Source: pip package version 1.1.2
Additional context Add any other context about the problem here.
Hi @nguyena2 are you able to provide us with more information (possibly the entire chat history if it doesn't contain sensitive info) about what is contained in the chat history and why the serialize/model dump would be failing?
@moonbox3 @markwallace-microsoft I can confirm that we are seeing this issue (or something similar) as well.
pf.flow.test failed with UserErrorException: PydanticSerializationError: Execution failure in 'agent': (PydanticSerializationError) Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'type'>
I am able to replicate this in the function calling stepwise planner starting in Semantic Kernel 1.2.0 simply by adding the SK Core Time Plugin to the kernel and asking a question that invokes any of those functions.
At the end of the process we use ChatHistory.model_dump_json() (same as is being called in ChatHistory.Serialize()) to output the steps taken by the planner and this is what is triggering the error. I am able to successfully use the ChatHistory.model_dump() to explore the Chat History object and I have not been able to identify anything about the payload itself that would be causing the serialization error.
I have replicated the behavior in Python 3.11 and 3.12, and can confirm that the issue can be resolved by moving the project back to Semantic Kernel 1.1.2.
If y'all feel that this is a separate issue, I am happy to document it in another Github Issue and I am available to demonstrate my example if so desired.
@moonbox3 @markwallace-microsoft I can confirm that we are seeing this issue (or something similar) as well.
pf.flow.test failed with UserErrorException: PydanticSerializationError: Execution failure in 'agent': (PydanticSerializationError) Error serializing to JSON: PydanticSerializationError: Unable to serialize unknown type: <class 'type'>I am able to replicate this in the function calling stepwise planner starting in Semantic Kernel 1.2.0 simply by adding the SK Core Time Plugin to the kernel and asking a question that invokes any of those functions.
At the end of the process we use
ChatHistory.model_dump_json()(same as is being called inChatHistory.Serialize()) to output the steps taken by the planner and this is what is triggering the error. I am able to successfully use theChatHistory.model_dump()to explore the Chat History object and I have not been able to identify anything about the payload itself that would be causing the serialization error.I have replicated the behavior in Python 3.11 and 3.12, and can confirm that the issue can be resolved by moving the project back to Semantic Kernel 1.1.2.
If y'all feel that this is a separate issue, I am happy to document it in another Github Issue and I am available to demonstrate my example if so desired.
Thanks for the extra context, @denny-nolan-kochcc. Tagging @eavanvalkenburg for visibility.
@nguyena2 and @denny-nolan-kochcc the issue is caused by a change we made so that the result in a FunctionResultContent can now be any type, instead of before where we cast everything to a string, which was limiting other use cases, so could you check the types used internally that are being put in there, you might also do [msg.to_dict() for msg in chat_history.messages] for inspection purposes, while I work on a fix.
@nguyena2 and @denny-nolan-kochcc the issue is caused by a change we made so that the
resultin a FunctionResultContent can now be any type, instead of before where we cast everything to a string, which was limiting other use cases, so could you check the types used internally that are being put in there, you might also do[msg.to_dict() for msg in chat_history.messages]for inspection purposes, while I work on a fix.
@nguyena2 and @denny-nolan-kochcc the issue is caused by a change we made so that the
resultin a FunctionResultContent can now be any type, instead of before where we cast everything to a string, which was limiting other use cases, so could you check the types used internally that are being put in there, you might also do[msg.to_dict() for msg in chat_history.messages]for inspection purposes, while I work on a fix.
what are we looking at in this screen @nguyena2 ?
These are the messages.to_dict(), how do I get the types?
Hello, could you tell us when you are going to fix that? Thanks,
What's the recommended approach for a work around until this gets fixed?
