Resources/Model training/Data preparation

Setting

Token limits and trimming

Every provider caps how many tokens one training example may contain. Long conversations over the cap are either trimmed — oldest exchanges removed first — or dropped.

Chapter 53 min read3 references

What it is

A model reads text as tokens, and training processes each example as one sequence of tokens. Providers set a per-example token limit: the longest sequence a single training record may contain. It is often smaller than the model's context window in normal use, because training needs memory not only for reading the tokens but also for computing how every weight should change.

Most support chats fit easily. The ones that don't are long troubleshooting threads, conversations where someone pasted a log file, or chats that carried on for an afternoon. Each of those needs a decision.

How it works

the budget
record tokens = system prompt + every earlier turn + the target reply
fits          = record tokens ≤ per-example limit

rough estimate: tokens ≈ characters ÷ 4   (English text)

Trim works backwards from the target reply. The system prompt and the target are always kept, then exchanges are removed starting from the beginning of the conversation until the total fits. Exchanges are removed whole — a user message together with the reply to it — so the record never starts with a dangling answer to a question that has gone.

systemYou are the support assistant for…250 · kept
user · asstExchange 1: setting up the account1,500 · trimmed
user · asstExchange 2: importing last year's data1,300 · trimmed
user · asstExchange 3: the import failed on row 2121,200 · kept
userSo how do I fix row 212?350 · kept
assistantRow 212 has a date in the wrong format. Change it to…600 · target, kept
A 5,200-token conversation and a 3,000-token limit. Trimming removes whole exchanges from the oldest end until the record fits, so the system prompt, the recent context and the target reply survive intact.

Why the oldest end? For most chats the most relevant context is the most recent: the question being answered, the error message just quoted, the last thing the assistant suggested. Research on long inputs also shows models use information at the start and end of their context better than material buried in the middle (Liu et al., 2023), so a shorter, focused record loses less than the token count suggests.

Drop excludes the record. Use it when the early part of a conversation is essential to the answer — for example, when the user states their account type or a key constraint in the first message and the target reply depends on it. A trimmed version of such a chat would teach the model to answer without information it actually needed, which is a quiet way to teach it to guess.

TrimTypical Default#

Remove the oldest exchanges until the record fits, keeping the system prompt, the latest context and the target. Keeps every example in the dataset.

Drop#

Exclude any record that is over the limit. Choose it when answers depend on details given early in long conversations, or when only a handful of records are affected.

Worked example: a 5,200-token thread and a 3,000-token limit
  1. The record holds a 250-token system prompt, three earlier exchanges of 1,500, 1,300 and 1,200 tokens, the user's question (350) and the target reply (600): 5,200 tokens.
  2. Remove exchange 1: 3,700 tokens. Still over.
  3. Remove exchange 2: 2,400 tokens. It fits, with 600 to spare.
  4. The trained-on record keeps the system prompt, exchange 3 (where the import error was quoted), the question and the answer — everything the target actually refers to.
  5. Had the user said “I'm on the legacy plan” in exchange 1 and the answer depended on it, Drop would have been the safer choice.

Why counts are estimates

Each model family has its own tokenizer, so the same sentence can be 20 tokens for one model and 24 for another. Counts shown before training are therefore estimates (English averages roughly four characters per token); the provider counts exactly when it receives the file. Code, numbers, URLs and non-English text usually take more tokens per character than plain English, so leave headroom when your data is heavy on any of those.

Common mistakes

  • Forgetting the system prompt is counted in every record: a 600-token prompt leaves 600 fewer tokens for the conversation.
  • Trimming chats whose answer depends on something said at the start, then wondering why the model invents account details.
  • Assuming the estimate is exact and running right up to the limit with code- or number-heavy data.
  • Ignoring how many records were trimmed: if it is most of them, the dataset may suit a model with a higher limit better.

References and further reading

External sources open in a new tab.

  1. 01Lost in the Middle: How Language Models Use Long ContextsLiu et al., 2023 · arXiv · arxiv.orgModels use information at the start and end of long inputs better than in the middle.
  2. 02Prepare data for fine-tuning your modelsAmazon Bedrock User Guide · docs.aws.amazon.comReal per-example token limits for several models, side by side.
  3. 03Prepare supervised fine-tuning data for Gemini modelsGoogle Cloud documentation · docs.cloud.google.comAnother provider's dataset requirements, including size limits.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.