I built an n8n workflow that looks at a sample of Gmail messages and suggests a practical set of labels. It checks the existing custom labels and creates any new ones it proposes, without changing the emails themselves.

The whole machine, all at once

1 workflow ยท 13 nodes

First, a look inside the inbox

I start the workflow manually whenever I want to review my email organization. From there, it splits into two branches: one gathers messages, and the other looks at the labels already in Gmail. That gives the category designer both the material to work with and the existing structure to respect. It is a bit like checking the assets in a scene before adding more. Nobody needs another copy of the same chair.

The email branch fetches a sample of up to 300 messages. An aggregate node then gathers those messages together instead of sending them through one at a time. For the AI analysis, I pass along each message's sender, subject and snippet. That gives the model a compact view of the sample. It is enough to look for patterns without asking it to design a category for every single email.

The sample is still just a sample, so I ask the model to consider what it might be missing. A handful of senders could dominate it, or automated messages could make one topic look more important than it really is. The prompt asks the model to take those possibilities into account when proposing categories. It also asks for observations about relevant limitations. A busy sender does not automatically get their own little kingdom.

Checking the labels already on the shelf

While the messages are being gathered, the other branch gets the Gmail labels. I filter that list to keep the custom labels, rather than feeding the designer every system label as if it were part of my own setup. The remaining labels are then collected together. This gives the model a view of what is already there. Starting from an existing scene is usually more useful than pretending the project is empty.

The workflow brings the two branches back together at the merge node. The message sample and the custom labels now travel as one input to the category designer. I arranged it this way so the model can compare its suggestions with the existing organization. It can reuse a label when it fits instead of proposing a second version of the same idea. That also means an existing label can stay even if the current sample does not happen to contain messages for it.

I ask the model to preserve the names and Gmail IDs of existing labels it keeps. New categories should only be proposed when they add something useful. The prompt also discourages unnecessary overlap with Gmail's native categories. It does not ask the model to rename, merge or delete the existing labels. The idea is to build around what's there, not rearrange the whole shelf every time I press the button.

Designing categories, not collecting them

The AI Category Designer takes the combined input and uses GPT-5.4 mini to propose the category structure. I ask it for the smallest practical set, rather than giving it a number of labels to fill. Broader, clearly defined categories are preferred over a long list of narrow ones. A topic appearing in the sample is not enough on its own to earn a label. Otherwise the inbox could end up with more categories than an overenthusiastic game inventory.

The prompt asks the model to consider the purpose and content of the messages, not just how often they appear. A relatively rare type of email can still justify a category if it is important or needs distinct handling. On the other hand, a frequent automated sender does not necessarily need a dedicated one. I also ask it to avoid categories based solely on a sender, product or service unless there is a strong reason. The aim is a structure that remains useful beyond the particular sample it saw.

Each proposed category comes with a description, inclusion and exclusion criteria, and a reason for its existence. Those criteria are intended to make the category understandable to another model that might classify future emails. The prompt allows an email to fit multiple categories when that genuinely makes sense. It also separates thematic categories from states or actions, such as whether a message has been read. The designer is making labels for types of email, not building an entire task manager.

A proposal the workflow can actually read

I connected a structured output parser to the category designer so its response can be handled by the rest of the workflow. The requested format is a JSON object, which is simply a structured way of returning the results. It contains a list of categories and a separate observations field. Each category has an action indicating whether it should be kept or created. That makes the next steps much easier than trying to interpret a paragraph of AI prose.

For an existing category, the requested output keeps its original name and label ID. For a new one, the label ID is left empty until Gmail creates the label. The model is told not to invent those IDs. It can also return an empty category list if it does not find anything justified. Sometimes the most useful thing a label maker can do is leave the label maker alone.

The model's role is limited to proposing the structure. The prompt treats email content as data rather than instructions and asks the model to ignore attempts inside messages to change its task. It also tells the model not to perform external actions itself. The actual Gmail operation happens later in the workflow, outside the model's proposal. That keeps the design step separate from the part that creates labels.

From proposal to Gmail labels

Once the proposal is ready, the workflow splits the category list into individual items. That lets the following nodes deal with each category separately. The filter then keeps the new categories intended for creation. Existing categories marked for keeping do not need to be created again. It is the workflow equivalent of checking the parts list before ordering another box.

The final Gmail node creates the labels that pass through the filter. This is the point where the proposal becomes a change in Gmail. The workflow is set up to create new labels, not to apply them to messages. It does not modify or delete emails, and it does not delete existing labels. The result is a label structure ready to use, without the workflow sorting the inbox on its own.

I like that the process starts with a manual run and finishes with a specific, limited action. The AI gets room to assess the sample, but the surrounding nodes decide how its structured proposal moves through the workflow. Existing labels provide context before the model makes suggestions. The split and filter then separate proposed additions from labels that are already there. It is a small pipeline, but each piece has a clear job.