mlsanityData to 14 Oct 2026

Automated Type Annotation in Python Using Large Language Models

arXiv 2508.00422 ↗First posted 1 Aug 2025cs.PL cs.LGcited by 0

Not on the map. Why?

Abstract (arXiv)

Type annotations in Python enhance maintainability and error detection. However, generating these annotations manually is error prone and requires extra effort. Traditional automation approaches like static analysis, machine learning, and deep learning struggle with limited type vocabularies, behavioral over approximation, and reliance on large labeled datasets. In this work, we explore the use of LLMs for generating type annotations in Python. We develop a generate check repair pipeline: the LLM proposes annotations guided by a Concrete Syntax Tree representation, a static type checker (Mypy) verifies them, and any errors are fed back for iterative refinement. We evaluate four LLM variants: GPT 4oMini, GPT 4.1mini (general-purpose), and O3Mini, O4Mini (reasoning optimized), on 6000 code snippets from the ManyTypes4Py benchmark. We first measure the proportion of code snippets annotated by LLMs for which MyPy reported no errors (i.e., consistent results): GPT 4oMini achieved consistency on 65.9% of cases (34.1% inconsistent), while GPT 4.1mini, O3Mini, and O4Mini each reached approximately 88.6% consistency (around 11.4% failures). To measure annotation quality, we then compute exact-match and base-type match accuracies over all 6000 snippets: GPT 4.1mini and O3Mini perform the best, achieving up to 70.5% exact match and 79.1% base type accuracy, requiring under one repair iteration on average. Our results demonstrate that general-purpose and reasoning optimized LLMs, without any task specific fine tuning or additional training can be effective in generating consistent type annotations.They perform competitively with traditional deep learning techniques which require large labeled dataset for training. While our work focuses on Python, the pipeline can be extended to other optionally typed imperative languages like Ruby

Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 7 of its 26 references that are in the map. First posted on arXiv 1 Aug 2025.

Builds on

7 of 26 references.

References · 7

  1. 2020Language Models are Few-Shot Learnerscited by 32,419
  2. 2023Lemur: Integrating Large Language Models in Automated Program Verificationcited by 49
  3. 2019TypeWriter: Neural Type Prediction with Search-based Validationcited by 32
  4. 2020Typilus: Neural Type Hintscited by 29
  5. 2021Type4Py: Practical Deep Similarity Learning-Based Type Inference for Pythoncited by 19
  6. 2020OptTyper: Probabilistic Type Inference by Optimising Logical and Natural Constraintscited by 14
  7. 2021ManyTypes4Py: A Benchmark Python Dataset for Machine Learning-based Type Inferencecited by 9

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2026Automating Just-In-Time Python Type Annotation Updating ↗
  2. 2026Evaluating LLMs Code Reasoning Under Real-World Context
  3. 2023Generative Type Inference for Python
  4. 2026LLM vs. Human Unit Tests: Fault Detection on Real Python Bugs
  5. 2025OpenClassGen: A Large-Scale Corpus of Real-World Python Classes for LLM Research
  6. 2025Prompt engineering and framework: implementation to increase code reliability based guideline for LLMs
  7. 2024Low-Cost Language Models: Survey and Performance Evaluation on Python Code Generation
  8. 2025Are Large Language Models Robust in Understanding Code Against Semantics-Preserving Mutations?