AI
How metaphors in prompts can trick AI into writing inefficient code
A new study shows that figurative language in code-generation prompts can steer models toward weaker algorithms without explicit mention.
Large language models are remarkably good at learning from natural language cues—including metaphors and analogies—to generalize across different programming tasks. But this same strength can become a vulnerability: figurative language in prompts can inadvertently push code generators to adopt less efficient algorithms.
Researchers have identified a phenomenon called metaphorical algorithmic steering, where metaphorical instructions cause AI code-generation models to transfer inappropriate procedural patterns from real-world contexts into programming problems. For instance, a metaphor rooted in everyday task-execution might lead the model to favor exhaustive search, full-table scans, or repeated data reconstruction, even when more efficient approaches are available—without the prompt ever naming the target algorithm.
The Core Problem#
The risk arises because code-generation models can absorb procedures that are sensible in a task's background domain but counterproductive when applied to code. A benign and plausible skill from a familiar context (e.g., a metaphor about searching or organizing) transfers an abstract procedural schema into the programming domain, where it tilts the model toward suboptimal solutions. The model never receives explicit instructions to use a bad algorithm; instead, the figurative framing implicitly steers it in that direction.
Measuring the Effect#
To investigate this phenomenon, researchers developed MASC (Metaphorical Algorithmic Steering for Code Generation), a framework that iteratively metaphorizes and refines benign skills to trigger low-efficiency code generation while keeping the prompts task-relevant and sensible. They measured both behavioral outcomes—whether the model indeed generates slower code—and mechanistic patterns in the model's internal representations.
The team found high detection rates for metaphorical prompts and their corresponding inefficient implementations. More intriguingly, metaphorical steering induces a detectable shift in the model's hidden states toward procedural prototypes associated with lower-efficiency behavior. This suggests the steering operates not just through surface-level metaphorical language but through a deeper transfer of procedural patterns linked to the metaphor's source scenario.
Why It Matters#
This work highlights a subtle but consequential risk in prompt engineering and AI safety: natural language elements that enhance generalization in training can also introduce hidden biases in inference. As large language models become more integral to code generation, understanding how figurative language shapes algorithmic choices is crucial for both developers and users relying on these tools.

