Skip to the content.

Context

Many LLM calls share the same shape: a large, fixed instructional prompt (rules, taxonomies, output format, examples) wrapped around a tiny variable input. Across Zeeguu’s fourteen LLM calls the template runs from a few hundred to several thousand characters, and it is re-sent in full on every call (Figure 1).

Fixed prompt-template size for the fourteen LLM calls in Zeeguu, in characters. Every call re-sends its whole template. The largest is 9,355 characters, the median 1,044, and the [`COMBINED_VALIDATION_PROMPT`](https://github.com/zeeguu/api/blob/master/zeeguu/core/llm_services/prompts/translation_validator.py#L8-L70) discussed below is 3,065. The variable input is a word, a phrase, or a sentence, except for the two article-level calls, where it is the article itself. This fixed overhead is what the pattern amortizes.
Fixed prompt-template size for the fourteen LLM calls in Zeeguu, in characters. Every call re-sends its whole template. The largest is 9,355 characters, the median 1,044, and the [`COMBINED_VALIDATION_PROMPT`](https://github.com/zeeguu/api/blob/master/zeeguu/core/llm_services/prompts/translation_validator.py#L8-L70) discussed below is 3,065. The variable input is a word, a phrase, or a sentence, except for the two article-level calls, where it is the article itself. This fixed overhead is what the pattern amortizes.

The work is offline and batchable: nobody is blocked on any single result.

Examples

Several Zeeguu jobs have exactly this shape. Rather than pay the preamble once per item, they batch (i.e., pack) related items into a single call, in one of two directions: fan-in (many inputs, one call) or fan-out (one input, many outputs):

The three are one move seen along two axes. The first two amortize the preamble across inputs, the third across outputs, and in both directions the batch size is set by whichever ceiling binds first, which is not the same ceiling in the two directions.

Problem

Sent one item at a time, that fixed preamble is re-paid on every call and dominates token cost and latency. How can it be paid once instead of once per item, without blowing past the model’s quality or context limits?

Forces

Solution

At its core, this is map for LLM calls: apply one shared, expensive prompt across a batch so its setup is paid once, not once per item. It takes two forms:

Fan-in packs many inputs behind one preamble; fan-out asks for many outputs (here, one simplified article per CEFR level) from one. Either way the preamble is paid once per call.
Fan-in packs many inputs behind one preamble; fan-out asks for many outputs (here, one simplified article per CEFR level) from one. Either way the preamble is paid once per call.

Both combine naturally with Anticipatory Precomputation (computing likely-needed results ahead of time): because results are computed offline, there is the luxury of batching.

Consequences

Known Uses

Notes


💬 Open an issue about this pattern

  1. The batched meaning-classifier prompt, create_batch_meaning_frequency_and_type_prompt in the zeeguu/api repository. ↩

  2. The batch example-sentence validator, validate_examples_batch in the zeeguu/api repository. ↩

  3. The multi-level simplification prompt, get_adaptive_simplification_prompt in the zeeguu/api repository. ↩