Metaphors Can Steer LLMs to Inefficient Code

Zhibo Hu, Chen Wang, Yanfeng Shu, Hye-young Paik, Liming Dong, Liming Zhu· August 3, 2026 View original

Key takeaways

  • Metaphorical instructions can lead LLMs to generate inefficient code.
  • This "algorithmic steering" transfers procedural patterns across domains.
  • The MASC framework detects and analyzes this phenomenon.
  • Model representations show a shift towards lower-efficiency behaviors.

Who benefits

Software DevelopmentAI EngineeringCybersecurityEducation

Summary

This research demonstrates that metaphorical instructions can implicitly transfer inefficient procedural patterns across domains, causing large language models to generate less efficient code. The study introduces MASC, a framework to detect and analyze this "metaphorical algorithmic steering."

Large language models (LLMs) often benefit from natural language elements like metaphors and analogies, which aid in generalization across different domains. However, this research reveals a downside: metaphorical expressions can inadvertently transfer inappropriate procedural patterns, leading to undesirable behaviors, particularly in code generation. The study shows that metaphorical instructions can steer LLMs towards less efficient algorithms, a phenomenon termed "metaphorical algorithmic steering." This steering occurs when a skill or procedure, benign and plausible in its source domain, transfers an abstract procedural schema into a programming task. This causes the LLM to favor inefficient methods like exhaustive search, full scans, or repeated reconstruction, even without explicit mention of these target algorithms. This suggests that LLMs can carry over procedures appropriate for a task's background domain into a programming context, resulting in suboptimal code. To investigate this, the MASC (Metaphorical Algorithmic Steering for Code Generation) framework was developed. MASC iteratively metaphorizes and refines benign skills to elicit low-efficiency code while maintaining task relevance. Beyond behavioral evaluation, the study found that this phenomenon is detectable and mechanistically reflected in model representations, with metaphorical skills inducing a hidden-state shift towards lower-efficiency procedural behavior prototypes.

Why it matters

For professionals developing or using LLMs for code generation, understanding how subtle linguistic cues can lead to inefficient outputs is critical for improving model reliability, performance, and resource optimization. It highlights a new challenge in prompt engineering and model safety.

How to implement this in your domain

  1. 1Audit prompt engineering: Review and refine prompts for code generation LLMs to identify and mitigate potential metaphorical algorithmic steering.
  2. 2Develop detection tools: Explore creating or using tools like MASC to detect inefficient procedural patterns in LLM-generated code.
  3. 3Educate developers: Train prompt engineers and developers on the risks of implicit procedural transfer from metaphorical language.
  4. 4Fine-tune models: Consider fine-tuning LLMs with datasets specifically designed to reduce sensitivity to metaphor-induced inefficiencies in code generation.

Original post by Zhibo Hu, Chen Wang, Yanfeng Shu, Hye-young Paik, Liming Dong, Liming Zhu

"arXiv:2607.28683v1 Announce Type: cross Abstract: Large language models benefit from elements in natural language, such as metaphors and analogies in training data and inference input to achieve generalisability across different domains. However, these language elements may also…"

View on X

Originally posted by Zhibo Hu, Chen Wang, Yanfeng Shu, Hye-young Paik, Liming Dong, Liming Zhu on X · view source

Want to go deeper?

Turn these trends into skills with Learnijoy's hands-on AI & tech courses.

Explore courses