#Structured Output Error

22 messages · Page 1 of 1 (latest)

humble flame
#

Good evening, the API is having an issue using client.chat.parse with a responseFormat for a structured output.
Yet, a few hours ago, it still worked.
Is anyone else experiencing this issue?

**Code : **


const { z } = require('zod');

const Book = z.object({
  name: z.string(),
  authors: z.array(z.string()),
});

const apiKey = "...";

const client = new Mistral({ apiKey: apiKey });

(async () => {
  const chatResponse = await client.chat.parse({
    model: "ministral-8b-latest",
    messages: [
      {
        role: "system",
        content: "Extract the books information.",
      },
      {
        role: "user",
        content: "I recently read 'To Kill a Mockingbird' by Harper Lee.",
      },
    ],
    responseFormat: Book,
    maxTokens: 256,
    temperature: 0,
  });

  console.log(chatResponse);
})();

**Output : **

SyntaxError: Unexpected token '`', "`\\`\\`json
{
"... is not valid JSON
    at JSON.parse (<anonymous>)
    at convertToParsedChatCompletionResponse (<...>\node_modules\@mistralai\mistralai\extra\structChat.js:34:63)
    at Chat.parse (<...>\node_modules\@mistralai\mistralai\sdk\chat.js:24:91)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async <...>\app.js:305:24
#

Structured Output Error

empty sluice
#

Yeah, I've had 2 chats on le chat through web interface stick in 'thinking mode' I can expand and see what was going to be the output... but I see a "\boxed{" near the end then a } ....

meager ferry
#

@green schooner quite urgent, a bug seems to have been released on structured outputs.

curl --location "https://api.mistral.ai/v1/chat/completions" \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header "Authorization: Bearer $MISTRAL_API_KEY" \ --data '{ "model": "ministral-8b-latest", "messages": [ { "role": "system", "content": "Extract the books information." }, { "role": "user", "content": "I recently read To Kill a Mockingbird by Harper Lee." } ], "response_format": { "type": "json_schema", "json_schema": { "schema": { "properties": { "name": { "title": "Name", "type": "string" }, "authors": { "items": { "type": "string" }, "title": "Authors", "type": "array" } }, "required": ["name", "authors"], "title": "Book", "type": "object", "additionalProperties": false }, "name": "book", "strict": true }'"temperature": 06,

{"id":"41fdc9d06ac74e0081c9ad81d300071b","created":1753946653,"model":"ministral-8b-latest","usage":{"prompt_tokens":21,"total_tokens":123,"completion_tokens":102},"object":"chat.completion","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","tool_calls":null,"content":"```json\n{\n \"properties\": {\n \"name\": {\n \"title\": \"Name\",\n \"type\": \"string\"\n },\n \"authors\": {\n \"items\": {\n \"type\": \"string\"\n },\n \"title\": \"Authors\",\n \"type\": \"array\"\n }\n },\n \"required\": [\"name\", \"authors\"],\n \"title\": \"Book\",\n \"type\": \"object\",\n \"additionalProperties\": false\n}\n```"}}]}

⚠️ The output choices[0].message.content returns the input structured !

meager ferry
#

The problem seems to occur with ministral-8b only, ministral-3b, large, medium, etc seem to be ok

humble flame
#

Any news yet ?

meager ferry
#

I tried contacting the support, but nothing on that side either..

humble flame
#

but they answered?

humble flame
#

I receive this from the IT Support :

We apologize for any inconvenience you may have experienced.

We have flagged this issue for further investigation by our engineers and will keep you updated on the outcome!

Thank you for your patience,
Mistral AI - Support Team

meager ferry
#

I have had no answer on my side, it just says "Ticket has been updated • 3h ago In progress"

#

Thanks for sharing !

green schooner
#

Update: the team is working on this 👍 will keep u updated

meager ferry
#

Thank you !

green schooner
#

@meager ferry and @humble flame should be fixed now, can u confirm?

meager ferry
#

I confirm, thanks !

slate cargo
humble flame
#

Yes !! Thanks @green schooner

mossy canyon
#

Hi,
I have the similar code,

import { Mistral } from "@mistralai/mistralai";
import { z } from "zod";

const Book = z.object({
  name: z.string(),
  authors: z.array(z.string()),
});

const apiKey = process.env.MISTRAL_API_KEY;

const client = new Mistral({ apiKey: apiKey });

const chatResponse = await client.chat.parse({
  model: "ministral-8b-latest",
  messages: [
    {
      role: "system",
      content: "Extract the books information.",
    },
    {
      role: "user",
      content: "I recently read 'To Kill a Mockingbird' by Harper Lee.",
    },
  ],
  responseFormat: Book,
  maxTokens: 256,
  temperature: 0,
});

when run,

/home/user/temp/mistral/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mistralai/mistralai/src/lib/schemas.ts:49
    return ERR(new SDKValidationError(errorMessage, err, rawValue));
               ^


SDKValidationError: Input validation failed: TypeError: Cannot read properties of undefined (reading '_zod')
    at safeParse (/home/user/temp/mistral/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mistralai/mistralai/src/lib/schemas.ts:49:16)
    ...
    maxTokens: 256,
    temperature: 0,
    responseFormat: {
      type: 'json_schema',
      jsonSchema: {
        name: 'placeholderName',
        schemaDefinition: {
          type: 'string',
          '$schema': 'http://json-schema.org/draft-07/schema#'
        },
        strict: true
      }
    }
  },
  rawMessage: 'Input validation failed'
}
green schooner
mossy canyon
#

I'm running the v1.7.5,

$ pnpm ls
Legend: production dependency, optional only, dev only

[email protected] /home/user/temp/mistral (PRIVATE)

dependencies:
@mistralai/mistralai 1.7.5
dotenv 17.2.1
zod 4.0.14

I still see the same issue after deleting node_modules and re-installed the packages.

green schooner
#

Thats a bit surprising, will take a quick look

mossy canyon
#

I suspect it could caused by the Zod. When I downgrade the Zod from v4 to 3.25.76, it throws

SDKError: API error occurred: Status 401 Content-Type application/json; charset=utf-8 Body 
{"detail":"Unauthorized"}
    at matchFunc (/home/user/temp/mistral/node_modules/.pnpm/@[email protected][email protected]/node_modules/@mistralai/mistralai/src/lib/matchers.ts:236:16)

but I can still run OCR API without any problem ...