JSON schema sometimes wrapped in array

41 views
Skip to first unread message

Nikita Malyschkin

unread,
Oct 20, 2025, 6:11:32 PMOct 20
to Chrome Built-in AI Early Preview Program Discussions
Hi everyone

So I've encountered this anomaly where the JSON schema response is sometimes wrapped in an array.

I've looked in chrome://on-device-internals/ logs and see the reponse being wrapped.
I was able to get wrapped and unwrapped results with identical session setup and prompt.

Having a look in the logs and seeing how the sausage is made I expect that this non deterministic behaviour is coming from the model directly. Maybe the injected prompt for enforcing schemas can be tweaked to behave more predictably.

Here's an example from the logs(input/output redacted):
Executing model with input context of 218 tokens: <user>[==user input==] Remember to respond in JSON that follows this "JSON Schema" specification: {"title":"string","acknowledgement":"string","question":"string"}<end><model>
Model generates raw response with PromptApi: [{"title":"[==title==]","acknowledgement":"[==acknowledgement==]", "question":"[==question==]"}]

For now, this is my workaround:
Screenshot 2025-10-21 at 00.08.14.png

Hope this saves someones time debugging their code :D

Thomas Steiner

unread,
Oct 20, 2025, 6:20:52 PMOct 20
to Nikita Malyschkin, Chrome Built-in AI Early Preview Program Discussions
Hi Nikita,

I saw a similar issue before and successfully addressed it by adding a concrete example output to my prompt (the API already repeats the JSON Schema [unless you explicitly omit this]). 

JSON Schema:

{
  "type": "object",
  "properties": {
    "hashtags": {
      "type": "array",
      "maxItems": 3,
      "items": {
        "type": "string",
        "pattern": "^#[^\\s#]+$"
      }
    }
  },
  "required": ["hashtags"],
  "additionalProperties": false
}

Example output:

{
  "hashtags": [
    "#pottery",
    "#dyi"
  ]
}

My prompt:

const result = await session.prompt(  
  `Suggest hashtags for this post:

${post}

Example response:

{
  "hashtags": [
    "#pottery",
    "#dyi"
  ]
}`,
  {  
    responseConstraint: schema,
  }
);



--
You received this message because you are subscribed to the Google Groups "Chrome Built-in AI Early Preview Program Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chrome-ai-dev-previe...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chrome-ai-dev-preview-discuss/ec5837db-dbb2-4974-b835-3f3a4c2bccban%40chromium.org.


--
Thomas Steiner, PhD—Developer Relations Engineer (blog.tomayac.comtoot.cafe/@tomayac)

Google Spain, S.L.U.
Torre Picasso, Pl. Pablo Ruiz Picasso, 1, Tetuán, 28020 Madrid, Spain

CIF: B63272603
Inscrita en el Registro Mercantil de Madrid, sección 8, Hoja M­-435397 Tomo 24227 Folio 25

----- BEGIN PGP SIGNATURE -----
Version: GnuPG v2.4.8 (GNU/Linux)

iFy0uwAntT0bE3xtRa5AfeCheCkthAtTh3reSabiGbl0ck
0fjumBl3DCharaCTersAttH3b0ttom.xKcd.cOm/1181.
----- END PGP SIGNATURE -----

Nikita Malyschkin

unread,
Oct 20, 2025, 6:33:20 PMOct 20
to Chrome Built-in AI Early Preview Program Discussions, Thomas Steiner, Chrome Built-in AI Early Preview Program Discussions, Nikita Malyschkin
Few-shot prompting is a great idea, thank you! :)
But this sounds like a problem for tomorrow 😄 😴
Reply all
Reply to author
Forward
0 new messages