Claudeとプロパティベーステストを用いたバグ発見
大規模ソフトウェアプロジェクトで、コードの一般特性を推論してバグを効率的に特定するエージェントを開発した。
キーポイント
Anthropicが開発したAIエージェントが、プロパティベーステストを用いてPythonエコシステムの主要パッケージ(NumPy、SciPy、Pandas)のバグを発見
従来の例ベーステストの限界を超え、コードの一般特性を推論し、自動的にテストケースを生成する手法を採用
AIが型注釈、docstring、関数名、コメントから特性を推論し、Hypothesisフレームワークでテストを自動生成
発見されたバグは手動検証後に開発者に報告され、一部は既に修正済み
2025年NeurIPS Deep Learning for Code Workshopで発表された研究成果で、MATSプロジェクトの成果
影響分析・編集コメントを表示
影響分析
この研究は、AIによる自動化されたソフトウェアテストの新たな可能性を示し、大規模なオープンソースプロジェクトの品質向上に貢献する実用的な応用を実証している。従来のテスト手法の限界を超えるアプローチとして、ソフトウェア開発プロセスにおけるAI活用の重要な進展と言える。
編集コメント
AIが実用的なソフトウェア品質向上ツールとして進化していることを示す具体例。研究から実装、実際のバグ発見まで一貫した成果が注目される。
Anthropicの研究者らは、大規模ソフトウェアプロジェクトにおけるバグを効率的に発見するAIエージェントを開発した。このエージェントは、Claudeを活用してコードから一般的な「プロパティ」(コードが常に満たすべき性質や不変条件)を推論し、プロパティベーステストと呼ばれる手法を適用することで、NumPy、SciPy、Pandasなどの主要なPythonパッケージに潜むバグを実際に発見することに成功した。発見されたバグは手動で精査された後、開発者に報告されており、いくつかは既に修正されている。
ソフトウェアからバグを完全に排除することは極めて困難である。従来の一般的なテスト手法は、開発者が特定の入力例と期待される出力を用意する「事例ベーステスト」だ。しかし、この方法では開発者が想定しなかったエッジケース(境界条件)のテストが漏れやすく、そのようなケースは実装時にも考慮されていない可能性が高い。
これに対し、プロパティベーステストは異なるパラダイムを取る。開発者は個々のテストケースではなく、「JSONのデシリアライゼーションはシリアライゼーションの逆操作である」といったコードの一般的な「プロパティ」と、そのプロパティが適用される入力の範囲(例:任意のJSONシリアライズ可能オブジェクト)を指定する。テストフレームワーク(この研究ではHypothesisを使用)は、ファジングに似た技術で有効な入力を自動生成し、そのプロパティが常に成り立つかどうかを検証し、反例(バグ)を探索する。これにより、開発者は個々のエッジケースを列挙する負担から解放され、より抽象的なレベルでコードの正しさを保証できる。
本研究で開発されたAIエージェントは、既存のコードを読み込み、型アノテーション、ドックストリング、関数名、コメントといった情報からプロパティを自律的に発見する。その後、そのプロパティを検証するプロパティベーステストを自動生成する。研究の焦点は、セキュリティ脆弱性に限らず、一般的なロジックバグの特定に置かれている。多くのセキュリティ脆弱性を引き起こすロジックバグのクラスは、このプロパティベーステストのアプローチで捕捉可能だからである。
この成果は、2025年のNeurIPS Deep Learning for Code Workshopで発表された論文で詳述されており、MATSプロジェクトの一環として実施された。このアプローチは、開発者が見落としがちな複雑なエッジケースを自動的に探索・テストできるため、ソフトウェアの信頼性向上に寄与する新たな可能性を示している。
原文を表示
red.anthropic.com Finding bugs across the Python ecosystem with Claude and property-based testing
Muhammad Maaz1,2, Liam DeVoe3, Zac Hatfield-Dodds2, Nicholas Carlini2 1MATS, 2Anthropic, 3Northeastern University
We developed an agent that can efficiently identify bugs in large software projects. To do this, our agent infers general properties of code that should be true, and then by applying property-based testing—a technique similar to fuzz testing—we are able to discover bugs in top Python packages like NumPy, SciPy, and Pandas. After extensive manual validation, we are in the process of reporting these bugs to the developers, several of which have already been patched.
For more information, read the full paper, take a look at the GitHub repository, or browse the bugs we found at our site.
Ensuring that programs are bug-free is one of the most challenging aspects of software engineering. Bugs frequently continue to lurk despite the developer’s best effort. The most common approach to testing code is with example-based tests: the developer writes out a specific example use-case, and then verifies that the actual output matches the expected output. For example, a developer might verify that a sort function called on the list [2, 10, 5, 4] would return the output [2, 4, 5, 10]. However, exhaustively covering a program with tests like this is challenging: bugs frequently remain in an edge case the developer did not test. After all, if a developer does not think to test an edge case, it is also likely the developer did not consider that case in the implementation!
In contrast, property-based testing is a software testing paradigm that aims to test whether a general property of the code holds for all (or most) inputs. A developer specifies a property or invariant about the program—for example, that JSON deserialization is the inverse of serialization—as well as a description of the kinds of inputs the property accepts (e.g., any JSON serializable objects). The property-based testing framework then automatically searches for a counterexample of this property by generating valid inputs as test cases using techniques similar to fuzzing. Since the developer specifies the general input domain, and not individual test cases, property-based testing frees developers from thinking of every edge case and allows them to operate at a higher level of abstraction.
In our paper that we presented at the 2025 NeurIPS Deep Learning for Code Workshop that was the result of a MATS project, we developed an AI agent that autonomously writes property-based tests for existing code. We directed the agent to discover properties by reading type annotations, docstrings, function names, and comments. The agent then wrote corresponding property-based tests using Hypothesis.
For this work, we focused on the problem of identifying bugs in general, and not just security vulnerabilities. Many classes of logic bugs that cause security vulnerabilities are amenable to property-based testing. For example, in a recent blog post we focused on identifying bugs in smart contracts; almost all of those vulnerabilities are the result of logic bugs. In the future we imagine that it may be possible to apply techniques such as the one we describe here to proactively identify bugs before deployment.
We used our agent and discovered hundreds of potential bugs in popular open-source Python repositories like NumPy, SciPy, and Pandas. In order to responsibly disclose these bugs and to ensure we don’t unnecessarily burden maintainers, we carefully reviewed each bug.
The review process we used is more laborious than we would otherwise implement for our own code reviews, but we strongly preferred to reduce the number of false positives. Our process was as follows: first, we only selected the highest priority bugs for review. We sent these potential bugs to be reviewed by three expert humans (for an average of one hour of review per bug). We then discarded any bug where any of the three manual reviewers were uncertain of its validity. Finally, we (the authors of this blog) manually reviewed each of the candidate bugs. Only if we were also confident in its correctness did we then manually file an issue with the maintainer of the repository. We have already filed several of these bug reports, and are in the process of filing many more.
We’ve made available all of our data, including bugs that have not yet been validated, and, for completeness, even bugs that we determined to be invalid, so that maintainers can look at them at this site. Over the coming weeks we intend to file many of these remaining bugs (after additional validation), as well as expand our project to additional PyPI projects.
example-based test def test_sort(): assert my_sort([1,3,2]) == [1,2,3] assert my_sort([1,0,-5]) == [-5,0,1] # property-based test in Hypothesis from hypothesis import given, strategies as st @given(st.lists(st.integers())) def test_sort(lst): result = my_sort(lst) for
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み