◉GEMINI LABJP
●NEON — Gemini 4 Neon went GA on 11/18, paid tier only, at $3.00 input / $15.00 output per 1M tokens●OFFICE — Since the same day you can pass Word, PowerPoint and Excel files straight to the API and pay only for the pages or sheets you pick●GEMINI 2.5 — gemini-2.5-pro and gemini-2.5-flash shut down on the API on 12/1, 12 days left●OAUTH — Users report that Gemini CLI's older sign-in route now fails without telling you why●AG IDE — Neon is now Antigravity's default, with a setup that plans on Neon and builds on Hydrogen●STRUCTURED — When Structured Output JSON breaks, check the schema, then the prompt, then your validator●NEON — Gemini 4 Neon went GA on 11/18, paid tier only, at $3.00 input / $15.00 output per 1M tokens●OFFICE — Since the same day you can pass Word, PowerPoint and Excel files straight to the API and pay only for the pages or sheets you pick●GEMINI 2.5 — gemini-2.5-pro and gemini-2.5-flash shut down on the API on 12/1, 12 days left●OAUTH — Users report that Gemini CLI's older sign-in route now fails without telling you why●AG IDE — Neon is now Antigravity's default, with a setup that plans on Neon and builds on Hydrogen●STRUCTURED — When Structured Output JSON breaks, check the schema, then the prompt, then your validator
Articles/Dev Tools
⟐ Dev Tools/2026-08-21Intermediate

Why My Length Limit Only Failed on the English Notifications, and the Width-Based Fit That Replaced It

I had Gemini write push notifications in Japanese and English, and only the English ones came out truncated on real devices. The culprit was measuring length in characters. Here are the measured widths and the post-generation fitting code that fixed it.

gemini121gemini-api291structured-output28i18npush-notificationtext-truncation

✦ Premium Article

A reader in the US wrote in during the third week of the rollout: the notification text stops mid-sentence.

The app is a wallpaper app I run on my own. It sends a short announcement whenever new pieces are added, in Japanese and English. Gemini writes the copy, and my prompt said, plainly, "keep it under 40 characters." The Japanese notifications had been landing perfectly every time, so I assumed the same instruction was doing its job for English.

Every device I had checked on was set to a Japanese locale. That is why I never saw it.

The problem was not the quality of Gemini's output. It was my choice of unit. Below is what I measured on the way to understanding that, and the implementation I ended up with.

The short version: I stopped asking the model to respect a length

Here is the shape of the current pipeline.

  1. Gemini is never told to be brief. Instead it returns two fields — lead and detail — as structured output.
  2. All length adjustment happens afterward, in deterministic code.
  3. The unit is display width, not character count, and the way width is counted changes per language.

The whole change is a move from "make the model obey" to "have the model return something that degrades gracefully, and do the trimming myself." Here is why.

The same sentence is more than twice as long in English

I started by measuring strings close to what I was actually shipping. Display width here means: every character whose East Asian Width property is W, F, or A counts as 2, everything else counts as 1.

LanguageCharactersDisplay widthText
ja3467新しい浮世絵の壁紙を8枚追加しました。歌川広重の東海道シリーズです。
en81818 new ukiyo-e wallpapers are now available, including Hiroshige's Tokaido series.
ja2549今週の追加分は葛飾北斎の富嶽三十六景から6枚です。
en7474This week we added 6 pieces from Hokusai's Thirty-six Views of Mount Fuji.

The same message: 34 characters in Japanese, 81 in English. A factor of 2.4.

Now apply a flat "under 40 characters" to both. Japanese gets to use 80 units of display width. English gets 40. The same number was acting as a limit twice as tight in one language as the other. The English copy was not losing information because the model ignored me. It was losing information because my instruction was unreasonable in English.

There is a second reason not to push this onto the model at all. Gemini works in tokens, and "40 characters" is not a quantity it can count accurately while generating. Writing maxLength into your response_schema did not change this in my setup — over-long values still came back, and passing schema validation turned out to be a different thing from fitting the display width. The moment you depend on the model for a length guarantee, your pipeline has an unbounded failure mode.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Be able to tell, in your own code, whether a character-count limit or a token limit is the thing quietly failing on your multilingual strings
✦Understand why the same sentence measures 67 in Japanese and 81 in English, and budget display width per language instead of guessing
✦Catch the class of bug where one locale ships truncated text for weeks before anyone reports it, using a check that runs before delivery
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Dev Tools2026-08-10
Finding the questions your help docs never answer, by asking Gemini to write the quiz
When support keeps asking something your help page already covers, generate questions from that page and check whether the page alone can answer them. A two-pass audit pipeline with call design and cost math.
⟐ Dev Tools2026-08-15
Before Adding New iPhone Widths, I Had Gemini Write Out the Branches I Already Had
Adding three new screen widths to four apps turned into an extraction job, not a rewrite. Here is why I let Gemini pull the branch table out of the source and kept every pass/fail decision in deterministic code.
◈ API / SDK2026-08-22
Once You Pass Twenty Mediation Groups, How Do You Find the Setting That Went Missing?
As ad mediation groups multiply, missing sources and type drift accumulate quietly. Here is the split I settled on: normalize the settings into one matrix, let code confirm the gaps, and send Gemini only the cells that need judgment.