VapiAI / web

68 stars 41 forks source link

OpenAIFunction parameter validation #59

Open remyma opened 3 weeks ago

remyma commented 3 weeks ago

Hello,

I think that JsonSchema interface is not complete.

https://github.com/VapiAI/web/blob/cb7f315e49889c84e1b03bfaa1664d14d6b62608/api.ts#L454

It's missing some properties useful for validation, for instance minLength, maxLength and format for string type: https://json-schema.org/understanding-json-schema/reference/string#format

That would help on the tool specification so that LLM is aware of expected format.

For instance, I have a tool function, with startDate and endDate parameters. This parameters should be date-time (type: string, format: date-time)

export const myFunction: OpenAIFunction = {
  name: 'myfunction',
  description: "...",
  parameters: {
    type: "object",
    properties: {
      startDate: {
        type: "string",
        description: "Start date.",
      },
      endDate: {
        type: "string",
        description: "End date.",
      },
    },
    required: ["startDate", "endDate"],
  },
};

Most of the time LLM call this function with correct format (2018-11-13T20:20:39+00:00) for parameters. But it already happened that LLM called my function with a wrong format (2018-11-13) instead of expected one.

If I could specify the format, that would fix the issue I think.

For now, I will specify it in the parameter description. But I think that would be great if the JsonSchema definition in Vapi could be fully compliant with JsonSchema.

Also in openAI doc there is an example with enums to enforce parameter validation: https://platform.openai.com/docs/guides/function-calling/use-enums-for-function-arguments-when-possible

I don't think we can have as much control on validation on Vapi.

What do you think?

nikhilro commented 3 weeks ago

We don't expose the full schema in types to not overwhelm people but entirety of it is supported it in the api. To unblock yourself, just use as any

remyma commented 3 weeks ago

ok, I'll do that. I understand your point about not overwhelming people, although I think it would be clearer to stick to the standard definition. It helps suggest to people that they may benefit from better validation of the parameters