Effect CommunityEC
Effect Community9mo ago
5 replies
Niklas

Error with `Schema.OptionFromNullishOr` and `Schema.OptionFromUndefinedOr` in Completions Structu...

I've noticed that I'm getting the error
ResponseError: StatusCode: {
      "error": {
        "message": "Invalid schema for response_format 'ExtractedExpenseReport': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'employeeEmail'.",
        "type": "invalid_request_error",
        "param": "response_format",
        "code": null
      }
    } (400 POST /chat/completions)

from completions.structured when I'm using a Schema.OptionFromNullishOr or Schema.OptionFromUndefinedOr. However, Schema.OptionFromNull works fine.

Below is my code example:
export class ExtractedExpenseReport extends Schema.Class<ExtractedExpenseReport>(
  "ExtractedExpenseReport"
)({
  employeeEmail: Schema.OptionFromNullishOr(Schema.String, null).annotations({
    description: "Email of the employee who submitted the report, optional",
  })}){}
...
Effect.gen(function* () {
        const plan = yield* AIPlan;

        const request = (input: string) =>
            pipe(
                Completions.Completions,
                Effect.flatMap((completions) =>
                    completions.structured({
                        input: `${instructions}${input}`,
                        schema: ExtractedExpenseReport,
                    }),
                ),
            );

Is that expected?
Was this page helpful?