[Bug]: cannot serialize pydantic model
What component(s) are affected?
- [x] Opik Python SDK
- [ ] Opik Typescript SDK
- [ ] Opik Agent Optimizer SDK
- [ ] Opik UI
- [ ] Opik Server
- [ ] Documentation
Opik version
- Opik version: master
Describe the problem
`Traceback (most recent call last): File "B:\code\gen1\backend\main.py", line 651, in extract_property_data result = await run_data_extraction(property, bucket) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "B:\code\gen1\backend\process.py", line 293, in run_data_extraction async for event in runner.run_async( File "b:\code\gen1.venv\Lib\site-packages\google\adk\runners.py", line 197, in run_async async for event in invocation_context.agent.run_async(invocation_context): File "b:\code\gen1.venv\Lib\site-packages\google\adk\agents\base_agent.py", line 133, in run_async async for event in self._run_async_impl(ctx): File "b:\code\gen1.venv\Lib\site-packages\google\adk\agents\llm_agent.py", line 246, in _run_async_impl async for event in self._llm_flow.run_async(ctx): File "b:\code\gen1.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 243, in run_async async for event in self._run_one_step_async(invocation_context): File "b:\code\gen1.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 268, in _run_one_step_async async for llm_response in self._call_llm_async( File "b:\code\gen1.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 453, in _call_llm_async if response := await self._handle_before_model_callback( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "b:\code\gen1.venv\Lib\site-packages\google\adk\flows\llm_flows\base_llm_flow.py", line 522, in _handle_before_model_callback before_model_callback_content = callback( ^^^^^^^^^ File "b:\code\gen1.venv\Lib\site-packages\opik\integrations\adk\opik_tracer.py", line 196, in before_model_callback input = adk_helpers.convert_adk_base_model_to_dict(llm_request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "b:\code\gen1.venv\Lib\site-packages\opik\integrations\adk\helpers.py", line 13, in convert_adk_base_model_to_dict return value.model_dump(mode="json", exclude_unset=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "b:\code\gen1.venv\Lib\site-packages\pydantic\main.py", line 426, in model_dump return self.pydantic_serializer.to_python( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'pydantic._internal._model_construction.ModelMetaclass'>
ERROR - main - HTTP 500: Error extracting property data: Unable to serialize unknown type: <class 'pydantic._internal._model_construction.ModelMetaclass'>`
Reproduction steps and code snippets
# Create combined model CombinedResponseSchema = create_model( 'CombinedResponseSchema', **all_fields, prompt_template=(str, combined_prompt), chain_of_thought=(Optional[str], None), __base__=ResponseSchema )
agent = LlmAgent( name="data_extraction_agent", model=MODEL, instruction= "Read the files and describe the !content! of the provided files by the user", #GENERAL_EXTRACTION_INSTRUCTIONS + combined_prompt + GENERAL_EXCTRACTION_NOTES, global_instruction="", output_schema=CombinedResponseSchema, disallow_transfer_to_parent=True, disallow_transfer_to_peers=True )
Error logs or stack trace
No response
Healthcheck results
No response
This happens if you provide response_schema to the agent. Then convert_adk_base_model_to_dict cannot execute it, because it runs value.model_dump on a class instead of instance
Hey @intval , thank you for reporting it! We'll look into it and update you
I'm getting the same thing.
Any updates on this bug? I'm currently unable to observe crucial ADK LlmAgent calls because of this. Anything I can do to assist?
Hi @intval, @stefanadelbert we were able to reproduce the issue and we will fix it shortly
Hi @intval, @stefanadelbert we shipped a fix in our ADK integration. Could you try updating the OPIK SDK and let us know if it fix the issue?