@cf/meta/llama-4-scout-17b-16e-instruct not returning valid JSON schema back

Hi guys, not sure if this is the right place to ask but i'm encounting a weird issue. I'm wanted to test out the Workers AI Batch, but for some reason i could not get this to work properly so i continued normal single messages. Right now i'm testing out the @cf/meta/llama-4-scout-17b-16e-instruct model with my code but i cant seem to get any 'valid' json response back: What am i doing wrong here? I tried multiple methods, but i cant seem to get any valid return to process further without fixing the response manually with another function.
{

evaluation: 'This ad is completely incorrect. The title mentions Playstation 3, but the
requested item is a GameBoy. The price is also listed as €0.00, which seems to be an error. The
picture is likely not of a GameBoy either.',
goodDeal: false
}
{

evaluation: 'This ad is completely incorrect. The title mentions Playstation 3, but the
requested item is a GameBoy. The price is also listed as €0.00, which seems to be an error. The
picture is likely not of a GameBoy either.',
goodDeal: false
}
My code:
const aiResp = await env.AI.run(
"@cf/meta/llama-4-scout-17b-16e-instruct",
{
messages,
response_format: {
type: "json_schema",
json_schema: {
name: "DealEvaluation",
schema: {
type: "object",
properties: {
evaluation: {
type: "string",
description:
"Brief explanation why this is or isn’t a good deal",
},
goodDeal: {
type: "boolean",
description: "Whether this is a good deal",
},
},
required: ["evaluation", "goodDeal"],
},
},
},
}
);
const aiResp = await env.AI.run(
"@cf/meta/llama-4-scout-17b-16e-instruct",
{
messages,
response_format: {
type: "json_schema",
json_schema: {
name: "DealEvaluation",
schema: {
type: "object",
properties: {
evaluation: {
type: "string",
description:
"Brief explanation why this is or isn’t a good deal",
},
goodDeal: {
type: "boolean",
description: "Whether this is a good deal",
},
},
required: ["evaluation", "goodDeal"],
},
},
},
}
);
1 Reply
SCALEXO
SCALEXOOP3mo ago
My message: (even with the extra context to return JSON, it not working)
const messages = [
{
role: "system",
content:
"You are a friendly assistant that evaluates second-hand ads.",
},
{
role: "user",
content: `
Evaluate this ad for a GameBoy under €${PRICE_LIMIT}:

Title: ${ad.title}
Description: ${ad.description}
Price: €${(ad.price_cents / 100).toFixed(2)}
Picture: ${ad.picture_url || "No image"}

Return JSON with exactly these fields:
{
"evaluation": string,
"goodDeal": boolean
}
No extra fields.
`,
},
];
const messages = [
{
role: "system",
content:
"You are a friendly assistant that evaluates second-hand ads.",
},
{
role: "user",
content: `
Evaluate this ad for a GameBoy under €${PRICE_LIMIT}:

Title: ${ad.title}
Description: ${ad.description}
Price: €${(ad.price_cents / 100).toFixed(2)}
Picture: ${ad.picture_url || "No image"}

Return JSON with exactly these fields:
{
"evaluation": string,
"goodDeal": boolean
}
No extra fields.
`,
},
];

Did you find this page helpful?