arXiv:2610.41617cs.SEOct 2026

Manuscript Offprint

arXiv:2610.41617

Prompt Less, Infer More: Static Analysis-Guided LLM Type Annotation for Python

Wonseok Oh, Michael Pradel, Hakjoo Oh

Wonseok Oh

Korea University

Seoul, Republic of Korea

wonseok_oh@korea.ac.kr

Michael Pradel

CISPA Helmholtz Center for Information Security

Stuttgart, Germany

michael@binaervarianz.de

Hakjoo Oh ∗^{*}

Korea University

Seoul, Republic of Korea

hakjoo_oh@korea.ac.kr

Abstract—Type annotations improve the maintainability and reliability of Python programs, but many real-world projects remain under-annotated because manual annotation is time-consuming and error-prone. Recent neural and LLM-based type inference systems can recover missing annotations, yet they often trade accuracy for efficiency. Existing approaches often fail to exploit project-wide type evidence, or do so inefficiently through unnecessary model calls and noisy prompts. We present SALT, an LLM-based type inference system guided by static analysis. SALT integrates static analysis with LLM inference to resolve types statically, prioritize LLM queries, and construct concise type-aware context. To demonstrate the effectiveness of SALT, we evaluated it on 12 real-world Python projects. SALT achieves the best accuracy among the evaluated systems and reduces estimated LLM cost by up to 78.5% compared with a strong coding-assistant baseline. It also shows similar cost savings with the frontier model GPT-5.5, demonstrating that SALT remains effective with strong LLMs.

Index Terms—Python type inference, large language models, static analysis, type annotation

I. INTRODUCTION

Type annotations have become an important part of modern Python development. Although Python is dynamically typed, type annotations allow developers to catch bugs with static checkers and make large codebases easier to maintain [1]. Unfortunately, many Python projects remain under-annotated [2], and manually annotating them is time-consuming and error-prone [3]. This problem has motivated a growing interest in automated type annotation for Python [4]–[22].

Existing Approaches. Recent work has explored specialized type inference tools based on neural [4]–[13] and LLM-based [14], [15] approaches, which show promise in annotating real-world Python code. More recently, general-purpose LLM coding assistants, such as AIDER [23], CLAUDE CODE [24], CODEX CLI [25], GITHUB COPILOT [26], and CURSOR [27], have become a natural alternative. Although these tools are not designed specifically for type inference, type annotation is also a code-editing task: a tool that can inspect a repository and modify code can be prompted to add missing annotations.

We observed that these assistants can achieve strong accuracy on a benchmark of real-world Python projects. As a preview of our results, the strongest existing specialized tool, TYPET5 [12], reaches 69.30% accuracy, while AIDER, an open-source coding assistant, reaches up to 84.13% accuracy. This result arises because AIDER can retrieve and reason about broad repository context, including cross-file evidence, whereas specialized systems tend to focus only on the target function or fail to make use of diverse contextual information.

However, this accuracy comes at a high cost. For a project with about 14k lines of code, AIDER with GLM-4.7 [28] consumed 24.83M input and 0.65M output tokens, costing approximately 57.67 1^{1}. First, AIDER invokes the LLM for every function, even trivial ones such as def foo(): return 0. Second, AIDER constructs context through lexical name matching rather than program analysis, producing verbose prompts that often include irrelevant information.

In summary, specialized tools are limited because they fail to capture relevant context, whereas general-purpose coding assistants are inefficient because they trigger unnecessary LLM invocations and flood the prompt with irrelevant information.

This Work. We present SALT, a system that uses Static Analysis to guide LLM-based Type annotation. SALT retains the broad repository-level reasoning of general-purpose coding assistants, but uses static analysis to reduce unnecessary LLM usage. SALT first performs project-wide forward and backward type inference. Forward inference propagates caller-side evidence, while backward inference recovers use-site evidence that flows from callees. When static evidence is sufficiently precise, SALT directly annotates the code without invoking an LLM. For unresolved functions, SALT uses the inferred type information to prioritize high-leverage LLM queries and to construct concise type-aware context for each target function.

Our evaluation on 12 real-world Python projects from TYPEBENCH [29] shows that this design improves both effectiveness and efficiency. We evaluate SALT with three LLM models of different sizes: Gemma 4 [30], gpt-oss [31], and GLM-4.7 [28]. Across three LLM models, SALT improves accuracy over AIDER by 3.5% on average while reducing LLM calls by 35.7%. In addition, SALT reduces estimated cost by 75.7% on average. SALT also remains effective with the frontier model GPT-5.5, reducing estimated cost by 74.8% while slightly improving accuracy over AIDER (also backed by GPT-5.5). Moreover, our ablation study shows that static analysis,

∗^{*}Corresponding author

1^{1}We calculate the cost based on the GLM-4.7 API pricing (https://www.cerebras.ai/pricing). Input: 2.25/M, Output: 2.75/M.

query prioritization, and type-aware context construction each improve accuracy and reduce LLM usage.

Contributions. This paper makes the following contributions:

  • We show that general-purpose coding assistants can outperform specialized type inference tools, but at substantial cost from unnecessary LLM calls and verbose context.

  • We present SALT, which uses static analysis to actively guide LLM-based annotation through (i) forward and backward inference, (ii) query prioritization, and (iii) concise type-aware context.

  • We evaluate SALT on 12 real-world Python projects with four LLMs, showing improved accuracy over strong baselines with up to 78.5% lower cost, including with the frontier model GPT-5.5.

References (34)