Skip to content

fix(oci): uppercase tool type field for OCI V2 API compatibility#758

Merged
daniel-cohere merged 5 commits intocohere-ai:mainfrom
fede-kamel:fix/oci-tool-type-uppercase
Apr 13, 2026
Merged

fix(oci): uppercase tool type field for OCI V2 API compatibility#758
daniel-cohere merged 5 commits intocohere-ai:mainfrom
fede-kamel:fix/oci-tool-type-uppercase

Conversation

@fede-kamel
Copy link
Copy Markdown
Contributor

@fede-kamel fede-kamel commented Apr 11, 2026

Summary

Fixes #759OciClientV2.chat() with tools parameter returns 400 from OCI Generative AI.

Root Cause

OCI Generative AI expects the tool type field as "FUNCTION" (uppercase), matching its convention for all enum fields (message roles, content types, etc.). The SDK passes through the Cohere format "function" (lowercase), causing:

status_code: 400, body: {'message': 'Please pass in correct format of request.'}

Fix

Transform tool type to uppercase when building the OCI request body, consistent with how we already transform message roles ("user""USER") and content types ("text""TEXT").

Integration test added

This bug shipped undetected because there was no integration test that called OCI with a tools parameter — existing tests only verified request/response transformation with mocked data. Added test_chat_tool_use_v2 which calls OCI on-demand with a tool definition and asserts:

  • Response is not None
  • finish_reason is "TOOL_CALL"
  • tool_calls list is non-empty
  • Tool call function name matches the defined tool (get_weather)
  • Tool call arguments contain the expected value ("Toronto")
tests/test_oci_client.py::TestOciClientV2::test_chat_tool_use_v2 PASSED
================ 46 passed, 13 deselected, 70 warnings in 9.83s ================

46/46 non-streaming tests pass. Streaming tests are deselected as the streaming termination fix is in a separate PR (#757).

Test plan

  • 46/46 OCI tests pass (excluding streaming tests which depend on fix(oci): terminate stream on finishReason — OCI does not send [DONE] #757)
  • New test_chat_tool_use_v2 integration test passes against OCI us-chicago-1
  • Tool use returns finish_reason=TOOL_CALL with correct tool_calls
  • tool_plan field populated correctly
  • Existing unit tests for tool message field transformation still pass

@daniel-cohere Tool use was broken on OCI because the type field needs to be uppercased like all other OCI enum values. Added the missing integration test so this can't regress.


Note

Medium Risk
Changes request/response transformations for OCI chat and embed (enum casing and embeddings field selection), which can affect API compatibility and output shape for existing integrations.

Overview
Fixes OCI on-demand compatibility by normalizing enum casing in request/response transforms: tools and message.tool_calls now uppercase their type when sending to OCI, while tool call type is lowercased on responses for Cohere compatibility; safety_mode is only sent when non-null and is uppercased.

Adjusts embeddings handling to match OCI behavior: embeddingTypes are now sent as lowercase, and embed responses now prefer embeddingsByType when present (falling back to embeddings). Adds integration tests covering V2 tool-use (including multi-turn tool results), safety_mode behavior, and embedding options like embedding_types and truncate.

Reviewed by Cursor Bugbot for commit 8b2706f. Bugbot is set up for automated code reviews on this repo. Configure here.

OCI Generative AI expects tool type as "FUNCTION" (uppercase) but the
SDK passes through the Cohere format "function" (lowercase), causing
a 400 error. Transform tool types to uppercase like we do for message
roles and content types.
The missing integration test allowed the tool type casing bug to
ship undetected. This test calls OCI with a tool definition and
verifies the response contains tool_calls with the correct function
name and arguments.
Fix remaining casing issues found during systematic audit:

- V1 tools: uppercase type field (same fix as V2)
- tool_calls in messages: uppercase type when sending tool results back
  in multi-turn conversations
- Response tool_calls: lowercase type from OCI's "FUNCTION" back to
  "function" for Cohere SDK compatibility
- safety_mode: uppercase defensively (CONTEXTUAL/STRICT/OFF)

Integration tests added for each:
- test_chat_tool_use_response_type_lowered: verifies tool_call.type
  is "function" (not "FUNCTION") in responses
- test_chat_multi_turn_tool_use_v2: full tool use round-trip (call →
  result → final response)
- test_chat_safety_mode_v2: verifies safety_mode works on OCI
Comment thread src/cohere/oci_client.py
…e response

- embedding_types: OCI expects lowercase (float, int8) not uppercase.
  The .upper() was breaking all embedding_types requests.
- Response: OCI returns "embeddingsByType" (not "embeddings") when
  embeddingTypes is specified. Handle both response keys.
- Unit test updated to expect lowercase.
- Integration tests added: embedding_types=["float"] and truncate modes.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 1f55765. Configure here.

Comment thread src/cohere/oci_client.py Outdated
@fede-kamel fede-kamel force-pushed the fix/oci-tool-type-uppercase branch from 1f55765 to 8f40152 Compare April 11, 2026 14:05
Address Cursor Bugbot review: safety_mode is Optional, so the SDK can
pass None when the user explicitly sets safety_mode=None. Guard with
a None check before calling .upper() on both V1 and V2 paths.
@daniel-cohere daniel-cohere merged commit fc167c1 into cohere-ai:main Apr 13, 2026
1 check passed
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.

fix: OCI tool use returns 400 — tool type field not uppercased

2 participants