Skip to content

ApigeeLlm Chat Completions crashes on typed tool result values #8131

Description

@1aifanatic

Describe the bug

ApigeeLlm's Chat Completions adapter calls json.dumps directly on tool responses. A normal Python tool returning a date, datetime, Decimal, UUID, or Pydantic model therefore crashes before sending the next HTTP request. This affects both streaming and non-streaming requests.

Reproduction

Use an ApigeeLlm configured for an OpenAI-compatible Chat Completions endpoint with this tool:

import datetime
from decimal import Decimal

def get_invoice() -> dict:
    return {'due': datetime.date(2026, 12, 1), 'total': Decimal('12.50')}

When the model calls get_invoice, the result becomes a FunctionResponse successfully, but conversion to the next Chat Completions request raises TypeError: Object of type date is not JSON serializable in CompletionsHTTPClient._contents_to_messages.

Expected: send valid JSON with the date encoded as an ISO string and Decimal encoded without losing precision, consistent with ADK's typed model values. Ordinary JSON results should remain unchanged.

Environment and validation

Reproduced on main at 12aab4aaa, Python 3.12.10, Windows. A real InMemoryRunner and FunctionTool were exercised against a local HTTP server emitting OpenAI-compatible responses, for both NONE and SSE streaming. No live Apigee deployment or provider credentials were used.

This is separate from #8123, which affects the LiteLlm adapter. Apigee has its own serializer and raises rather than falling back to a Python repr. The proposed fix uses the already-installed Pydantic serializer only for values unsupported by the standard JSON encoder.

Prepared with AI assistance; reproduction and validation were executed locally.

Activity

  1. surajksharma07 commented on Nov 18, 2026

    @surajksharma07
    Collaborator

    @1aifanatic. Reproduced this on 2.14.1 and current main (also on 1.27.2) with a local fake endpoint: the get_invoice result fails at apigee_llm.py:850 before the second request goes out.

    As a workaround I passed default=lambda o: to_jsonable_python(o, by_alias=False, bytes_mode='base64') to that json.dumps call. The tool message then came through as {"due": "2026-12-01", "total": "12.50"}, and plain dict results were unchanged.

    Could you check that this matches what you see on your side, including SSE? It’s also worth trying a nested Pydantic model and bytes, since those take the base64 path.

    Once it holds up in your testing, please take #8134 out of draft so it can go to review. It would be good to keep the options in line with the Gemma fix and #8125.

  2. added
    models
    on Nov 29, 2026
  3. added
    wip
    on Dec 3, 2026
  4. self-assigned this
    on Dec 3, 2026
  5. willie3838 commented on Dec 3, 2026

    @willie3838

    Hey @1aifanatic thanks for contributing to this! An internal team will be taking over from here and your work will be credited.

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

Metadata

Metadata

Labels

modelswip

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions