Debug Gemini Nano

Published: February 28, 2025

Built-in AI relies on Gemini Nano to perform inference for all of the APIs. Sometimes, Gemini Nano may return an error message or otherwise fail to return the result you expect. You can review debug information for all built-in AI APIs that use Gemini Nano. This includes the Prompt API, the Summarizer API, the Writer API, and the Rewriter API.

  1. Open Chrome and go to chrome://on-device-internals.
  2. Select Event Logs.
  3. (Optional) Click Dump to download a JSON file with all of the event information.

You can file a bug so we can address this error in our implementation.

Example: Debug the Prompt API

For example, in the following session the user requested rhyming words from the Prompt API.

const session = await ai.languageModel.create({
  systemPrompt: "You are an API endpoint that returns rhymes as JSON for an input word."
});

await session.prompt([
  { role: "user", content: "house" },  
  { role: "assistant", content: "{\"input\": \"house\", \"output\": \"mouse\"}" },
  { role: "user", content: "file"},  
]);

The model's response was as follows, formatted for legibility:

```json
[]
```

**Reasoning:**

The input you provided (empty arrays) is an empty list or array in JSON format.
When you try to find rhymes for an empty list, you're essentially looking for
words that rhyme with nothing.


Therefore, there are no rhymes to return. The JSON response will be an empty
array `[]`."

Why did the model not return a JSON message with a rhyming word, ideally, {"input": "file", "output": "pile"}? Although structured output isn't implemented yet at the time of this writing, the response should at least somehow perform the rhyming task.

To debug this error, visit chrome://on-device-internals/ and go to the Event Logs tab. The log reveals that the problem was in the model's interpretation of the prompt. Instead of JSON, the model understood the input as a string: [object Object],[object Object],[object Object].

Here's the complete debug message, formatted for legibility:

Executing model with input context of 0 tokens:
<system>You are an API endpoint that returns rhymes as JSON for an input word.<end>
with string: <user>[object Object],[object Object],[object Object]<end> <model>

The Event Logs tab of the special page chrome://on-device-internals with debugging information.

We added this information to a bug for the model issue, Prompt API seems to run toString() on JSON input, which helped the engineering team identify the issue.

Share feedback

Share your debugging feedback by filing a bug report.