mistralai/client-python

Tool definition with 'required' parameter fails API validation

thehunmonkgroup opened this issue · 1 comments

Not sure where to file this, as I think it's an API bug, hopefully here will work.

It seems the API validation is rejecting tools that are defined with a required parameter:

Error response 422 while fetching https://api.mistral.ai/v1/chat/completions:

{
  "object": "error",
  "message": {
    "detail": [
      {
        "type": "extra_forbidden",
        "loc": [
          "body",
          "tools",
          0,
          "function",
          "required"
        ],
        "msg": "Extra inputs are not permitted",
        "input": [
          "content"
        ]
      }
    ]
  },
  "type": "invalid_request_error",
  "param": null,
  "code": null
}

This is my tools configuration:

[
    {
        'type': 'function',
        'function': {
            'name': 'reverse_content',
            'description': 'Reverse the provided content',
            'parameters': {
                'type': 'object',
                'properties': {
                    'content': {
                        'type': 'string',
                        'description': 'The content to reverse.'
                    }
                }
            },
            'required': ['content'] # <-- THIS ARG REJECTED
        }
    }
]

The examples at https://docs.mistral.ai/capabilities/function_calling/#tools clearly show that required is a valid parameter, and in line with the JSON Schema spec.

When I remove required and keep everything else the same, the tool call completes successfully.

I figured this out, required needs to go under parameters, not function.

With that change, everything is working.