Skip to content

fix(models): send ApigeeLlm tool parameters as JSON Schema - #8431

Open
omkarbandikatte wants to merge 1 commit into
google:mainfrom
omkarbandikatte:fix/apigee-tool-parameters-json-schema
Open

omkarbandikatte wants to merge 1 commit into
google:mainfrom
omkarbandikatte:fix/apigee-tool-parameters-json-schema

Conversation

@omkarbandikatte

Copy link
Copy Markdown

Link to Issue or Description of Change

No existing issue; describing the change below.

Problem:

CompletionsHTTPClient._function_declaration_to_tool (used by ApigeeLlm for OpenAI-compatible Chat Completions endpoints) converts FunctionDeclaration.parameters with func.parameters.model_dump(exclude_none=True). For a types.Schema that produces Gemini's representation, not JSON Schema: uppercase type names and snake_case field names.

{"type": "OBJECT", "required": ["tags"],
 "properties": {"tags": {"type": "ARRAY", "items": {"type": "STRING"}, "min_items": 1},
                "mode": {"any_of": [...]}}}

A Chat Completions endpoint expects "object", "array", minItems, anyOf, and so on; with these keys, unions and constraints are ignored or the request is rejected. This affects any tool declared with parameters=types.Schema(...), including ModelConsultTool. The response schema in the same file is already converted with model_dump(by_alias=True, mode='json') and lowercase_schema_types (#7920), but tool parameters weren't.

Solution:

Dump tool parameters with by_alias=True, mode='json' and apply lowercase_schema_types, the same conversion as the response schema. parameters_json_schema is still passed through unchanged.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

New test_construct_payload_tool_schema_parameters_as_json_schema in tests/unittests/models/test_completions_http_client.py builds a payload for a tool with an array (min_items) and an any_of parameter and checks the exact JSON Schema sent. It fails on main and passes with this change.

$ pytest tests/unittests/models/test_completions_http_client.py tests/unittests/models/test_apigee_llm.py
248 passed

pyink, isort and ruff (pre-commit versions) are clean.

Manual End-to-End (E2E) Tests:

I don't have access to an Apigee proxy, so I checked the request payload built by CompletionsHTTPClient rather than a live call.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • 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.

An AI coding assistant helped find this and draft the change; I reviewed it and ran the tests myself.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant