Swagger spec GET parameter name contains brackets

Hi all,

I’m running into an interesting issue with a GET request defined in my Swagger spec. The name of the GET query parameter contains curly braces. The parameter is called zip (that square is supposed to be an open bracket followed by a close bracket). While the parameter is explicitly defined as a string, GPT treats it as an array. Here’s the Swagger definition:

                {
                    "name": "zip[]",
                    "in": "query",
                    "required": false,
                    "schema": {
                        "type": "string"
                    },
                    "description": "The zip code."
                },

And here is an example of GPT trying to pass the parameter:

{
  "zip": [
    "11001"
  ],
  "other key": "other value",
  "another key": "another value"
}

What GPT should be passing is:

{
  "zip[]": "11001",
  "other key": "other value",
  "another key": "another value"
}

A example request to the API would look like:

https://my.api/endpoint?zip[]=11001&zip[]=11002&other=parameter&another=parameter

Any idea how to get around this bug?

Have you tried escaping the [ and ]?

1 Like

I’ve tried escaping the brackets with backslashes, although that doesn’t work. I don’t believe you need to escape brackets provided they within quotes in a JSON…

Hi RAvirani, Have you tried including the above in the system prompt as a “this is an example return format for for zip” ?

I’ve tried defining zip like so:

                {
                    "name": "zip[]",
                    "in": "query",
                    "required": false,
                    "schema": {
                        "type": "string"
                    },
                    "description": "The person's zip code.  This parameter can be used more than once in the URL, for example: /endpoint?zip[]=11001&zip[]=11002"
                },

Is this what you mean?

No, I mean in the system prompt area, include an example of how you want the function returned, see if that influences the reply formatting, unless I have read this wrong, it looks like the model is returning the syntax incorrectly?

1 Like

I’m not sure what you mean by system prompt area…do you mean in the message sent when interacting with ChatGPT? And yes, ChatGPT is sending something like this to the API:

{
  "zip": [
    "11001"
  ],
  "other key": "other value",
  "another key": "another value"
}

…when it should be sending this:

{
  "zip[]": "11001",
  "other key": "other value",
  "another key": "another value"
}

This is probably interpreted as “zip” (and its an empty list subarray that you should fill with the multiple zips that are permitted, naturally).

Lets do a rewrite of both your parameter name and the description:

parameter
name: zip_codes_string
description: concatenate zip codes into string, formatted as 'zip[]=90210&zip[]=97101' (omit quotes)

ChatGPT proof of concept:

Instruction: concatenate zip codes into string, formatted as 'zip[]=90210&zip[]=97101' (omit quotes); [98301, 98303, 98532]
ChatGPT

Sure, I’ll concatenate the zip codes into the required format. Here’s the result:

"zip[]=98301&zip[]=98303&zip[]=98532"

1 Like

This solution worked for me - thank you!