Skip to content

Conversation

iamzimozic
Copy link
Contributor

@iamzimozic iamzimozic commented Oct 9, 2025

Description

The core fix is to enhance the Pydantic serialization within the base ChatMessage class to explicitly handle the Google SDK's FunctionCall object. The _recursive_serialization method in llama_index/core/base/llms/types.py is updated to check for this specific external object type and convert it into a standard Python dictionary using its internal .to_dict() method. This prevents the PydanticSerializationError from being thrown when the ChatMessage is dumped to JSON for storage.

Fixes # (issue)

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 9, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 9, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to commit this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it was intented for local testing only. I have deleted the file now.

from llama_index.core.schema import ImageDocument
from llama_index.core.utils import resolve_binary

GOOGLE_FUNCTION_CALL_AVAILABLE = False
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to import types from google here

serializable_tool_calls = []
for tc in original_tool_calls:
# If we find a FunctionCall object, convert it to a dict
if isinstance(tc, FunctionCall):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check for FunctionCall, we should be checking for whatever the root type of FunctionCall is

Looking at the source code, its a base model. Which is actually already being checked in self._recursive_serialization(value) -- but I think its not recursing nicely into the pydantic object?

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Oct 10, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 10, 2025
@iamzimozic
Copy link
Contributor Author

  1. Core: Fixed Generic Pydantic Serialization in types.py
    Problem: The initial issue was a PydanticSerializationError when handling nested Pydantic models (like Google's FunctionCall) inside additional_kwargs.

Solution: I fixed a recursion bug in the _recursive_serialization helper function. The corrected logic now properly handles any nested BaseModel, making the serialization robust and generic. This is a more durable fix than adding a special case for a single type.

  1. memory-mem0: Resolved Pydantic Compatibility Issues
    Problem: Tests for mem0 failed on all Python versions with an AttributeError. Debugging revealed that despite running on Pydantic v2, the model validator was being called in a backward-compatible v1 style, receiving a plain dict instead of a ValidationInfo object.

Solution: I updated the validator logic in mem0/base.py to work with a dict (changing values.data.get() to values.get()), aligning the code with its actual runtime behavior and resolving the crash.

  1. readers-web: Added Dependencies & Fixed PackageNotFoundError
    Problem: The test suite for readers-web was failing due to numerous ModuleNotFoundError errors and a PackageNotFoundError in the OxylabsWebReader test.

Solution:

I added all missing development dependencies (markdownify, lxml[html_clean], playwright, selenium, oxylabs, etc.) to the package's pyproject.toml, which are now tracked in the updated poetry.lock file.

To fix the PackageNotFoundError, I made the OxylabsWebReader code more robust by wrapping the version() call in a try...except block. It now defaults to a "local" string instead of crashing when run in a local test environment.

  1. graph_rag/cognee: Pinned Dependency to Stable Version
    Problem: Tests for cognee failed on Python 3.11+ due to a Pydantic v2 AttributeError inside the external cognee library.

Solution: Since we can't fix the external dependency, I pinned cognee-python to an older, stable version (0.1.26) in the package's pyproject.toml to avoid the buggy code.

@iamzimozic
Copy link
Contributor Author

The last fix passed all the checks but when "[Merge branch 'main' into fix/postgresV2]" happened, this showed up in every unit test
1 packages had test failures:
llama-index-integrations/graph_stores/llama-index-graph-stores-kuzu
this wasn't showing up earlier. Please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants