Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to have z.record part of structured outputs #1196

Closed
1 task done
lifeiscontent opened this issue Nov 19, 2024 · 2 comments
Closed
1 task done

add ability to have z.record part of structured outputs #1196

lifeiscontent opened this issue Nov 19, 2024 · 2 comments
Labels
openai api Related to underlying OpenAI API

Comments

@lifeiscontent
Copy link

Confirm this is a feature request for the Node library and not the underlying OpenAI API.

  • This is a feature request for the Node library

Describe the feature or improvement you're requesting

I'm currently working on a tool that provides edits to records the shape looks like:

model: string[][]

updates to model: Record<number, Record<number, string>>

the reason why this shape is ideal is because we can keep an in-memory lookup of all the "rows" and "columns" that have been edited and z.record is a good use case for this shape because we obviously don't need the entire array to be returned, just the edits. currently when using strict: true inside of a run, this kind of schema fails.

Additional context

No response

@silasalberti
Copy link

The OpenAI API doesn't support objects with dynamic fields (i.e. Record<number, string>): https://platform.openai.com/docs/guides/structured-outputs#additionalproperties-false-must-always-be-set-in-objects
So this is a current limitation of the OpenAI API, not the SDK.

A pragmatic workaround would be something like this:

model: z.array(
  z.object({
    row: z.number(),
    columns: z.array(
      z.object({
        column: z.number(),
        value: z.string(),
      }),
    ),
  }),
),

@RobertCraigie RobertCraigie added the openai api Related to underlying OpenAI API label Jan 17, 2025
@RobertCraigie
Copy link
Collaborator

Thanks for feature request, as Silas mentioned, this is a limitation imposed by the API so there's nothing we can do in the SDK unfortunately so I'm going to close this.

@RobertCraigie RobertCraigie closed this as not planned Won't fix, can't repro, duplicate, stale Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openai api Related to underlying OpenAI API
Projects
None yet
Development

No branches or pull requests

3 participants