genkit-plugins icon indicating copy to clipboard operation
genkit-plugins copied to clipboard

Getting literal schema responses since Genkit 0.9.x and corresponding plugin version 0.11.0

Open TAxdorff opened this issue 1 year ago • 0 comments

Affected plugin(s)

  • [ ] Anthropic
  • [ ] Azure OpenAI
  • [ ] Cohere
  • [ ] Convex
  • [ ] Groq
  • [ ] Mistral
  • [x] OpenAI

Describe the bug Inconsistently (happens often, but never consistently) get literal Schema format responses from generate calls:

Provided data:

{
  "type": "object",
  "properties": {
    "plaintextFullText": "Diet 15 FL OZ 222 ml\n\n",
    "markdownFullText": "# Diet Coke\n\n**Volume:** 15 FL OZ (222 ml)\n\n"
  },
  "required": [
    "plaintextFullText",
    "markdownFullText"
  ],
  "additionalProperties": true,
  "$schema": "http://json-schema.org/draft-07/schema#"
}

Instead the response should have just been the fields within 'properties'.

Required JSON schema:

{
  "type": "object",
  "properties": {
    "plaintextFullText": {
      "type": "string",
      "description": "Full plaintext document ... special characters."
    },
    "markdownFullText": {
      "type": "string",
      "description": "Full markdown document ... markdown formatting."
    }
  },
  "required": [
    "plaintextFullText",
    "markdownFullText"
  ],
  "additionalProperties": true,
  "$schema": "http://json-schema.org/draft-07/schema#"
}

To Reproduce Send requests using zod schema with this generate statement:

            const generate_response = await ai.generate({
                model: model,
                system: requestDetails.system_prompt,
                prompt: [...textPrompt, ...mediaPrompts],
                config: config,
                output: {schema: outputSchema, format: "json"}
            });

            const data = generate_response.output;

This is shared between calls to gemini and openAI, and worked consistently in older plugin and genkit versions (0.5.17 genkit + <=0.10.1 plugin)

It still works consistently with gemini as well

Expected behavior Response should just be

{
   "plaintextFullText": "...",
   "markdownFullText": "...",
}

Screenshots N/A

Plugin(s) version: Started occurring during 0.10.1 -> 0.11.0 genkitx-openai plugin transition

Currently 0.12.0 genkitx-openai

Genkit version: Started occurring during 0.5.17 -> 0.9.4 transition with Genkit

Currently using 0.9.12

Additional context Mostly using 4o and 4o-mini models

Schema definition passed into variable outputSchema:

export const MarkdownFullTextSchema = z.object({
    plaintextFullText: z.string().describe("Full plaintext document ... escape special characters."),
    markdownFullText: z.string().describe("Full markdown document ... markdown formatting."),
});

export type MarkdownText = z.infer<typeof MarkdownFullTextSchema>;

TAxdorff avatar Jan 08 '25 21:01 TAxdorff