Nested properties in tool/function parameters not supported in Responses API

Responses API responds with an error like There was an issue with your request. Please check your inputs and try again if there is an included tool/function schema property that itself has properties. I.e. nested properties. This is not a problem in Completions API.

The following tool schema is fine in Completions API, but results in an error in Responses API:

{
  "function": {
    "description": "some tool.",
    "name": "some_tool",
    "parameters": {
      "properties": {
        "cited_claims": {
          "description": "A list of citations to be added to the response which link claims to source texts and quotes.",
          "items": {
            "properties": {
              "citation": {
                "properties": {
                  "document_chunk_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "default": null,
                    "description": "The id of the document node or chunk."
                  },
                  "document_name": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "default": null,
                    "description": "The name of the document."
                  },
                  "file_id": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "default": null,
                    "description": "The id of the document."
                  },
                  "page": {
                    "anyOf": [
                      {
                        "type": "integer"
                      },
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "default": null,
                    "description": "The page number, url of the webpage, etc."
                  },
                  "quote": {
                    "description": "The verbatim text to cite from a document or webpage.",
                    "type": "string"
                  },
                  "url": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "default": null,
                    "description": "The url of the webpage."
                  }
                },
                "required": [
                  "quote"
                ],
                "type": "object"
              },
              "claim": {
                "description": "The claim which is supported by the citation. Should be verbatim text from the response. A response may contain multiple claims, and thus multiple Citations.",
                "type": "string"
              }
            },
            "required": [
              "claim",
              "citation"
            ],
            "type": "object"
          },
          "type": "array"
        },
        "response": {
          "description": "The final response which contains one or more claims that need to be cited. This will be the tool's output",
          "type": "string"
        }
      },
      "required": [
        "response",
        "cited_claims"
      ],
      "type": "object"
    }
  },
  "type": "function"
}

If the nested properties are removed, there is no error. E.g.:

{
  "function": {
    "description": "some tool.",
    "name": "some_tool",
    "parameters": {
      "properties": {
        "cited_claims": {
          "description": "A list of citations to be added to the response which link claims to source texts and quotes.",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "response": {
          "description": "The final response which contains one or more claims that need to be cited. This will be the tool's output",
          "type": "string"
        }
      },
      "required": [
        "response",
        "cited_claims"
      ],
      "type": "object"
    }
  },
  "type": "function"
}

It looks like this is an issue with the way that Pydantic creates JSON schemas.

When a pydantic field has a definition like some_field: str | None = None, Pydantic’s model_json_schema() will create a schema like:

{
    "anyOf": [
        {
            "type": "string"
        },
        {
            "type": "null"
        }
    ],
}

rather than

{
    "type": ["string", "null"],
}

Responses API will only work with the latter, whereas Completions API would handle either format.

Read more about why Pydantic formats in this way in this issue #7161 in pydantic’s repo on github (can’t include a link here).

1 Like