StoryCoder: Narrative Reformulation for Structured Reasoning in LLM Code Generation

Geonhui Jang, Dongyoon Han, YoungJoon Yoo · 2026

Read StoryCoder: Narrative Reformulation for Structured Reasoning in LLM Code Generation by Geonhui Jang, Dongyoon Han, YoungJoon Yoo (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2604-14631.txt.

Introduction

Jang, Han, and Yoo propose StoryCoder, a system that recasts code-writing questions as coherent natural-language narratives instead of leaving problem details scattered. Each narrative holds a task summary, constraints, and example test cases, shaped by the chosen algorithm and genre. Across 11 models on those three benchmarks, they lift zero-shot pass-at-10 by 18.7 percent on average, a steady gain. Beyond accuracy, narratives steer models toward correct algorithmic strategies, cut implementation errors, and yield more modular code, with gains hinging on narrative coherence and genre alignment.

Catalog record

CREATORGeonhui Jang, Dongyoon Han, YoungJoon Yoo
YEAR2026
COLLECTIONPAPERS
FORMATTXT
FILE SIZE60667
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2604.14631

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

StoryCoder: Narrative Reformulation for Structured Reasoning in LLM Code Generation Geonhui Jang, Dongyoon Han, YoungJoon Yoo Abstract Effective code generation requires both model capability and a problem representation that carefully structures how models reason and plan. Existing approaches augment reasoning steps or inject specific structure into how models think, but leave scattered problem conditions unchanged. Inspired by the way humans organize fragmented information into coherent explanations, we propose StoryCoder , a narrative reformulation framework that transforms code generation questions into coherent natural language narratives, providing richer contextual structure than simple rephrasings. Each narrative consists of three components: a task overview, constraints, and example test cases, guided by the selected algorithm and genre. Experiments across 11 models on HumanEval, LiveCodeBench, and CodeForces demonstrate consistent improvements, with an average gain of 18.7 % 18.7\% in zero-shot pass@10. Beyond accuracy, our analyses reveal that narrative reformulation guides models toward correct algorithmic strategies, reduces implementation errors, and induces a more modular code structure. The analyses further show that these benefits depend on narrative coherence and genre alignment, suggesting that structured problem representation is important for code generation regardless of model scale or architecture. Our code is available here . 1 Introduction Problem-solving ultimately depends on how clearly the information is conveyed and understood. Effective problem solving may require both the solver’s capability to interpret information and the way the problem is framed ( 31 ; 15 ) . However, in practice, task descriptions are incomplete or ambiguous, forcing solvers to infer missing details from context. These gaps are especially challenging in complex tasks that demand contextual understanding or multi-step reasoning. Large language models (LLMs) face the same difficulty: their performance depends not only on internal reasoning but also on how effectively the task is specified and interpreted ( 16 ) . In this work, we investigate how to improve the delivery and interpretation of information in LLMs, focusing on code generation tasks. Programming tasks are particularly suitable for this study: they are built on logically distinct structures, and their solutions can be explicitly validated using test cases, making them ideal for examining how problem representation affects reasoning ( 32 ; 20 ) . We introduce StoryCoder , a narrative-based prompting method that transforms short, instruction-like problem statements into coherent natural language. This design is based on the findings of cognitive science that humans comprehend and reason more effectively when organizing fragmented conditions into coherent mental models using analogical structures ( 14 ; 6 ; 10 ) . In this framework, models identify the appropriate algorithm that will form the logic of the code, align it with a suitable narrative genre, and reformulate it into a story with three sections: task overview, constraints, and example input/output. (Figure 1 ) By connecting fragmented conditions into coherent descriptions, narratives help LLMs capture context and follow more structured reasoning. We evaluate StoryCoder on three benchmarks across 11 closed- and open-source models. Extensive experiments demonstrate consistent performance gains across diverse models and benchmarks. Beyond overall accuracy, we find that narrative prompts substantially increase the likelihood of selecting the correct algorithms and reduce implementation errors. In contrast, when narratives are expressed in mismatched genres, performance drops significantly. This suggests that LLMs are sensitive to narrative structure and benefit from genre alignment in tasks such as code generation. These observations support our hypothesis that narratives are a natural and effective tool to encourage integrative reasoning. Our key contributions are as follows: • We propose StoryCoder , a narrative-based prompting method for code generation that reformulates fragmented prompts into coherent descriptions. • We demonstrate consistent empirical improvements across diverse models and benchmarks, achieving a 18.7\% average gain in zero-shot pass@10 accuracy. • We provide quantitative analyses showing that narrative reformulation guides LLMs toward correct algorithmic strategies, reduces implementation errors, and induces more modular code structure. Figure 1: Overview of StoryCoder framework. Given a question Q_{i} , (i) model first identifies an algorithmic category and selects a narrative genre, then (ii) reformulates the problem into a structured narrative \mathcal{N}_{i} consisting of task overview, constraints, and example input/output, and (iii) passes the narrative (optionally concatenated with Q_{i} ) to a solver model to generate code solutions, which are then verified with test cases. 2 Related Work Structured prompt engineering for code generation. Recent work in code generation has increasingly focused on structuring prompts to improve the reasoning process of LLMs. Some approaches introduce explicit intermediate steps, such as control structures or modular subcomponents, to guide program synthesis more reliably ( 18 ; 17 ; 11 ) . Recent work demonstrates that language-based input–output patterns can enable structured and verifiable reasoning in code generation ( 19 ) . Related studies further investigate how narrative or prose-style problem descriptions affect requirement extraction, using narrative framing as a condition to be evaluated in code generation ( 9 ) . While many previous approaches present structured reasoning through explicit intermediate steps or modular decomposition, our method StoryCoder provides a structured reasoning trajectory to the model through narrative-based prompt design. Prompt reformulation and test-time reasoning in LLMs. Another line of research examines how rephrasing prompts at test time affects the way LLMs reason on a task. Chain-of-thought prompting, especially when combined with self-consistency, helps models explore diverse reasoning paths and improves robustness through output aggregation ( 34 ; 33 ) . Beyond explicit reasoning steps, rephrasing task instructions influences how the model interprets the problem ( 5 ; 37 ) . In the context of multiple-choice reasoning tasks, narrative-based prompting has been explored as a structured reasoning framework to support the selection of answers among predefined choices ( 24 ) . Building on these insights, our method reformulates prompts into coherent task-grounded narratives that integrate conditions, intent, and examples within a unified structure for code generation. Figure 2: Example of narrative reformulation. The narrative representation bridges problem description and model reasoning, guiding the model from inefficient non-optimal solutions toward algorithmic strategies. 3 StoryCoder : Reformulating question into narratives 3.1 Conventional baselines for code generation Early evaluations of code generation relied on similarity-based metrics such as CodeBLEU, which were insufficient for assessing functional correctness. Recent benchmarks adopt execution-based evaluation using the pass@ k metric ( 3 ) . Under this setting, we consider the following baselines: Repeated Sampling, Paraphrasing, and Chain-of-Thought (CoT) prompting. • Repeated sampling improves pass@ k by generating multiple outputs for the same input via stochastic decoding, typically with high temperature ( 3 ) . Increasing the number of candidates raises the likelihood that at least one solution is correct. • Chain-of-thought (CoT) prompts the model to generate intermediate reasoning steps prior to producing code ( 34 ; 11 ) . By making the reasoning process explicit, CoT encourages stepwise planning. • Structured chain-of-thought (SCoT) extends CoT for code generation by incorporating program structures (sequence, branch, and loop) into the intermediate reasoning steps ( 18 ) . It guides the model to think from the perspective of the source code before generating the output. 3.2 Narrative reformulation for deeper comprehension The approaches discussed in Section 3.1 are useful, but they have a limitation: they either expand outputs without changing the input, or introduce reasoning steps that do not always reflect how models actually process the problem (

Read the complete text