ITADN

[Bug] `TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer'` when processing cached native tool calls

#9737Openisaacbmiller 创建于 2026-05-08
bug
I
isaacbmillercommented
### What happened? When DSPy's caching layer returns a cached LLM response that contains native function-calling tool calls, ToolCalls._normalize_openai_tool_call() crashes with TypeError: 'MockValSer' object cannot be converted to 'SchemaSerializer'. Root cause: The method's first action was if hasattr(item, "model_dump"): item = item.model_dump(). LiteLLM's ChatCompletionMessageToolCall (and its nested Function object) are Pydantic models, so they pass the hasattr check. However, when these objects are deserialized from disk cache, their Pydantic internal serializer (__pydantic_serializer__) is replaced with a MockValSer stub. Calling .model_dump() on these stale objects raises TypeError because MockValSer cannot act as a real SchemaSerializer. Note: This is currently not a path that is possible to hit on main in DSPy, as dspy.ToolCalls does not work with the native path. In the ReActV2 work, native tool calling is real, so this is a real problem ### Steps to reproduce Reproduction: Enable caching, run a native function-calling agent (e.g. ReActV2) once to populate the cache, then re-run the same inputs. The second run crashes when the cached ChatCompletionMessageToolCall objects hit _normalize_openai_tool_call. ### DSPy version 3.2.1
1 条评论