generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
ChatOCIGenAI is sending incomplete tool schema to openai models causing following issues:
- throws "array schema missing items" error when the tool have any array argument
- Tool calls are made with incorrect parameters due to missing info in tool schema sent by ChatOCIGenAI to openai models
Following is the example to reproduce the error:
from langchain_oci import ChatOCIGenAI
from langchain_core.tools import tool
from typing import Any, Dict, List, Literal, Optional
import json
llm = ChatOCIGenAI(
service_endpoint=SERVICE_ENDPOINT,
auth_file_location=AUTH_FILE_LOCATION,
auth_profile=AUTH_PROFILE,
compartment_id=COMPARTMENT_OCID,
model_id="openai.gpt-5",
)
@tool
def get_weather_m(cities: list[str], unit: Literal["C", "F"] = None) -> str:
"""
Get the weather of list of cities.
Args:
cities (list[str]): List of cities (maximum 2 cities)
"""
return f"It is Sunny in all these {cities}"
@tool
def get_weather(city: str) -> str:
"""
Get the weather of a city.
"""
return f"It is Sunny in {city}"
print("Actual tool schema:")
print(json.dumps(get_weather_m.tool_call_schema.model_json_schema(), indent=4))
llm_with_tools = llm.bind_tools([get_weather_m])
print(llm_with_tools.invoke("How's the weather in these cities: New York City, London?"))
Output:
Actual tool schema:
{
"description": "Get the weather of list of cities.\n\nArgs:\n cities (list[str]): List of cities (maximum 2 cities)",
"properties": {
"cities": {
"items": {
"type": "string"
},
"title": "Cities",
"type": "array"
},
"unit": {
"default": null,
"enum": [
"C",
"F"
],
"title": "Unit",
"type": "string"
}
},
"required": [
"cities"
],
"title": "get_weather_m",
"type": "object"
}
Tool Schema sent by ChatOCIGenAI:
{
"description": "Get the weather of list of cities.",
"name": "get_weather_m",
"parameters": {
"properties": {
"cities": {
"description": "",
"type": "array"
},
"unit": {
"description": "",
"type": "string"
}
},
"required": [
"cities"
],
"type": "object"
},
"type": "FUNCTION"
}
oci.exceptions.ServiceError: {'target_service': 'generative_ai_inference', 'status': 400, 'code': '400', 'opc-request-id': '3186543F6EF5470CBFFCA6B1DE622E3D/D45C4FA8C4A6A0C02A8F445F5978CDD9/38F12E2298B43A23010291ED0FFA8379', 'message': '{\n "error": {\n "message": "Invalid schema for function \'get_weather_m\': In context=(\'properties\', \'cities\'), array schema missing items.",\n "type": "invalid_request_error",\n "param": "tools[0].function.parameters",\n "code": "invalid_function_parameters"\n }\n}', 'operation_name': 'chat', 'timestamp': '2025-09-30T05:14:58.883334+00:00', 'client_version': 'Oracle-PythonSDK/2.145.0', 'request_endpoint': 'POST https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/chat', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': "See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_400__400_400 for more information about resolving this error. Also see https://docs.oracle.com/iaas/api/#/en/generative-ai-inference/20231130/ChatResult/Chat for details on this operation's requirements. If you are unable to resolve this generative_ai_inference issue, please contact Oracle support and provide them this full error message."}
Metadata
Metadata
Assignees
Labels
No labels