Skip to the page
Tecyfy

Prompting interview question · hard

Given a scenario where a language model is generating repetitive responses, which prompt engineering terms and techniques would you apply to address this issue?

The short answerI'd find out what kind of repetition it is (words looping within one answer, the same answer to different questions, or the same structure every time) and then fix it with clearer instructions, varied examples, better context and, where the model allows, decoding settings such as frequency and presence penalties or sampling.

The full answer

I'd find out what kind of repetition it is (words looping within one answer, the same answer to different questions, or the same structure every time) and then fix it with clearer instructions, varied examples, better context and, where the model allows, decoding settings such as frequency and presence penalties or sampling.

1. Diagnose the type

  • Loops within a response: the same sentence or phrase repeats. Usually a decoding issue, often with greedy or low-temperature decoding on smaller or open models.
  • Same content across requests: different inputs get near-identical answers. Usually the prompt dominates the input, or the input isn't reaching the model properly.
  • Same structure or phrasing: every answer starts "Great question!" or follows one template. Usually copied from examples or instructions.
  • Repetition in long conversations: the model repeats earlier answers as history grows.

2. Prompt techniques

  • Explicit instructions: "Don't repeat points already made. Each bullet must add new information." State it positively too: "Vary sentence openings; start directly with the answer."
  • Diverse examples: if all few-shot examples share a structure or phrase, outputs will too. Vary them, or say the examples show content, not wording.
  • Give more specific context: generic inputs produce generic, similar outputs; include the details that should make each answer different.
  • Ask for distinct items: "Give five ideas that differ in X, Y and Z" and "List them, then check none overlap" reduce near-duplicates.
  • Manage conversation history: summarise or trim long histories so earlier answers don't get echoed.
  • Set length appropriately: asking for more text than the content supports produces padding and repetition.

3. Decoding settings (where the model accepts them)

  • Temperature and top-p (nucleus sampling): greedy or very low-temperature decoding is prone to loops; Holtzman and colleagues showed sampling from the nucleus reduces such degeneration.
  • Frequency penalty: lowers the probability of tokens in proportion to how often they've appeared, discouraging repeated lines (OpenAI's API, range −2 to 2).
  • Presence penalty: lowers the probability of any token that has already appeared, encouraging new topics.
  • Repetition penalty and no-repeat n-gram size: in Hugging Face Transformers, for open models; the n-gram setting forbids any sequence of n tokens from occurring twice. Use small values and test: strong penalties make text unnatural, for example avoiding necessary repeated terms such as names or code identifiers. Many newer hosted models fix these settings, leaving the prompt as the main lever.

4. Structural fixes

  • Generate items one at a time, passing the list so far and asking for something different.
  • Post-process: remove duplicate sentences or items with code, or by comparing embeddings.
  • Try another model: some are more prone to repetition than others.

5. Measure Track a repetition metric (repeated n-grams per response, or similarity between answers to different inputs) on a test set before and after each change.

Last updated 16 October 2026