Purrx

Why LLMs can't place things on a slide

Ask Gemini to position every box on a slide with exact coordinates, check the result with code, and see why AI slide generators need a layout engine.

12 min+25 XPHands-on

A slide file stores every text box as a position and a size: x, y, width and height. So the obvious way to generate slides with AI is to ask the model for those numbers. It seems to work in a quick demo. Then you look closely.

Model picks x, y, w, h

Layout engine picks them

Left: coordinates chosen by a model. The title runs off the edge, cards overlap, one card falls off the bottom, and text overflows its box. Right: the same content laid out by code.

Why the numbers go wrong

  • The model can't measure text. Whether "Labor shortages are the number one reason" fits in a 200-point box at 22pt depends on the width of every letter in the font. The model has no way to work that out, so it guesses.
  • The numbers depend on each other. Three cards with gaps between them have to add up to the slide width. Change one width and every x after it is wrong. Language models are unreliable at this kind of running arithmetic.
  • The model never sees the result. It writes numbers and moves on. Nothing tells it that two boxes or that text spills off the slide.

Checking with code

In this exercise, findProblems() is already written for you (open its tab to read it). It uses nothing but arithmetic: does a box leave the slide, does its text need more lines than the box can hold, do two boxes overlap. Your job is the part that asks Gemini for the boxes.

You'll ask for JSON with a schema, exactly like the structured output lesson in Course 1, so the reply is guaranteed to be parseable.

Under the hood — How does findProblems estimate the number of lines?

It assumes an average character is about half the font size wide, so a box w points wide fits roughly w ÷ (fontSize × 0.5) characters per line. Lines are about 1.2 × the font size tall. That's a rough estimate, and even so the model's boxes usually fail it. In Module 5 you'll replace estimates like this with real measurements from the font.

The Slides tab draws exactly the boxes the model chose, so you can see the problems, not just read them. From the next module on, the model stops choosing positions entirely.

Key takeaways

  • A model can't measure text, so it can't know whether words fit the box it picked.
  • Coordinates depend on each other: one wrong number shifts everything after it.
  • The fix is to let the model describe structure and let code do the geometry.

Sign in to run the exercise

Reading is free. Writing code here needs an account so we have somewhere to keep your Gemini key and the +25 XP you are about to earn.