Analogical prompting

On this page 7

Analogical prompting is a prompting technique in which a large language model is instructed to recall or generate relevant example problems and their solutions on its own, and then use them as guidance to solve the target problem. Within artificial intelligence, it belongs to the family of reasoning-oriented prompting methods and combines the strengths of few-shot prompting and chain-of-thought reasoning without requiring a human to write any examples.

The idea draws on analogical reasoning in human cognition: when people meet an unfamiliar problem, they often ask themselves which similar problem they have solved before. Analogical prompting asks the model to perform that same recall step explicitly in its output, so the self-generated exemplars are tailored to each individual problem rather than fixed across all inputs.

How analogical prompting works

Analogical prompting works by inserting a self-generation step before the answer. A single prompt tells the model to first describe several relevant problems, explain how each was solved, and only then solve the problem at hand. Everything happens in one model call, so no retrieval system or example database is needed.

A typical instruction reads: recall three relevant and distinct problems, describe each problem and its solution, then solve the initial problem. Asking for distinct exemplars matters, because near-identical examples add tokens without adding guidance.

The table below breaks the method into its stages and explains what each one contributes.

StageWhat the model doesWhy it helps
Problem statementReads the target problemAnchors all later recall to the actual task
Exemplar recallWrites several similar problemsActivates relevant knowledge from training
Exemplar solutionsSolves each recalled problem step by stepRehearses a reasoning pattern before use
Optional knowledge stepStates core concepts or a short tutorialSupplies high-level principles, not only cases
Target solutionSolves the original problemTransfers the rehearsed pattern to the new case
Stages of an analogical prompt

Variants and key parameters

Analogical prompting has two main variants. The basic form generates exemplars only, while an extended form also asks the model to produce high-level knowledge, such as the key concept or algorithm a problem requires, before writing exemplars. The extended form tends to help on harder tasks such as competitive programming, where recognizing the right technique matters more than seeing a similar surface problem.

Several parameters shape results. The following table lists the most influential ones and typical settings.

ParameterTypical settingEffect of changing it
Number of exemplarsThree to fiveFewer gives less guidance; more adds cost with diminishing returns
Distinctness requirementExplicitly requestedPrevents repetitive exemplars that waste tokens
Knowledge stepEnabled for complex tasksImproves recognition of the underlying method
Output structureLabeled sections or delimitersMakes the final answer easy to extract
Model scaleLarge, capable modelsSmall models often recall irrelevant or wrong examples
Parameters that affect analogical prompting

How it compares with other prompting techniques

Analogical prompting sits between zero-shot chain-of-thought and manual few-shot prompting. It keeps the zero effort of zero-shot methods while recovering much of the guidance that hand-written examples provide, and its exemplars adapt to each input instead of staying fixed.

TechniqueSource of examplesMain strengthMain weakness
Analogical promptingGenerated by the model per problemTailored guidance with no labelingLonger outputs and recall errors
Zero-shot chain-of-thoughtNoneSimplest to applyNo demonstration of solution style
Few-shot chain-of-thoughtWritten by a humanPrecise, verified demonstrationsFixed examples may not fit every input
Auto-CoTClustered from a question poolAutomated, diverse exemplarsNeeds a dataset of questions
Step-back promptingNone; derives principles firstStrong on concept-heavy questionsNo worked cases to imitate
Generated knowledge promptingModel-generated factsAdds background contextFacts are not worked solutions
Analogical prompting and related techniques

In published evaluations on mathematical reasoning, code generation and logical reasoning benchmarks, analogical prompting matched or outperformed both zero-shot and manual few-shot chain-of-thought on average with large models. Gains are task- and model-dependent, so results on one benchmark should not be assumed to transfer to every workload.

When to use analogical prompting

Analogical prompting is most useful when good examples would help but are expensive to write or vary too much between inputs. The decision table below summarizes common situations.

SituationRecommendationReason
Diverse math or logic problemsUse analogical promptingEach problem receives fitting exemplars
Algorithmic coding tasksUse the knowledge-plus-exemplar variantNaming the right technique guides the code
Narrow task with stable formatPrefer curated few-shot examplesVerified examples are cheaper and safer
Strict latency or token budgetPrefer zero-shot chain-of-thoughtSelf-generated exemplars add many tokens
Small or weak modelAvoid or test carefullyRecalled examples are often unreliable
Choosing analogical prompting by situation

A practical approach is to evaluate against a baseline on a representative test set. Analogical prompting should earn its extra tokens with measurably better accuracy, not merely look more thorough.

Limitations and common mistakes

The central weakness is that self-generated exemplars are not verified. A model can recall a plausible-looking problem with a flawed solution and then transfer the flaw to the target answer, which makes errors look more confident because they arrive with supporting cases.

  • Higher token cost: three solved exemplars can multiply output length several times.
  • Irrelevant analogies: surface similarity, such as shared wording, can mislead the model toward the wrong method.
  • Answer extraction problems: without clear delimiters, downstream code may parse an exemplar answer instead of the final one.
  • Possible memorization effects: on public benchmarks, recalled exemplars may echo training data, which can inflate measured gains.
  • Hidden reasoning in production: long exemplar text often needs to be stripped before showing results to end users.

The idea in brief

Analogical prompting asks an AI model to remember similar problems first and then solve the new one. It is like a student who faces a tricky exam question. The student thinks of a few homework problems that looked alike and recalls how those were solved. Then the student applies the same approach.

Nobody has to write the practice examples for the model. It creates them itself, so they fit each question. The catch is that its memories can be wrong. A good check on the final answer is still needed.

A practical scenario

A company that builds a tutoring application for high school mathematics needs step-by-step solutions for thousands of word problems covering probability, geometry and algebra. Writing curated examples for every problem type would take an editor weeks, and a fixed set of examples fits geometry questions poorly when the input is about probability.

The engineering team switches to an analogical prompt that asks the model to recall three distinct related problems with solutions, state the key concept, and then solve the student’s problem inside a clearly labeled final section. The application displays only that final section, while the recalled exemplars stay in the logs for review.

On an internal test set of 500 problems checked by teachers, the team observes fewer reasoning errors than with zero-shot prompting, at roughly three times the output tokens. Because some recalled exemplars contain mistakes, the team adds an automated answer check against a symbolic solver, and problems that fail the check go to human review before students see them.