Texas State University
Towards Characterizing Machine Learning Contracts using Large Language Models
Abstract
dc:description.abstractMachine Learning (ML) contracts formally describe expected behavior and constraints before calling ML APIs. In practice, developers rely on incomplete docs or informal Q&A, leading to subtle misuses and contract violations. We address this by using Retrieval-Augmented Generation (RAG) with large language models (LLMs) to automatically characterize multi-label ML contracts from Stack Overflow posts: semantically similar, labeled examples are retrieved and paired with a concise taxonomy primer to produce structured labels across multiple levels. Beyond labeling, we additionally synthesize executable Python PyContracts with brief natural-language summaries and actionable fixes, and validate them via a lightweight Judge LLM plus a human-in-the-loop review that ensures contracts reproduce the reported fault and then pass after minimal repair. Our approach achieves up to 0.86 F1-score on challenging labels, processes posts in 3–5s at low cost, produces insights rated 75–80% relevant but only 25–30% actionable, and both GPT and Claude reach 100% executable PyContracts after guided repair. On a human-annotated corpus, retrieval-guided prompting improves label quality, and the contract stage attains high compile/run rates while guiding targeted fixes. This provides a practical bridge from informal Q&A to enforceable, verified ML contracts. We demonstrate practical utility through a VS Code extension that integrates our RAG-based contract detection and PyContract generation directly into the development workflow, enabling real-time violation detection, automated contract synthesis with iterative feedback loops, and interactive violation analysis with comprehensive label explanations.
Degree
thesis:*- Name thesis:degree_name
- Master of Science
- Level thesis:degree_level
- Masters
- Discipline thesis:degree_discipline
- Computer Science
- Department thesis:degree_department
- Computer Science
- Grantor
- Texas State University
- Year dc:date.issued
- 2025
Author and committee
dc:creator, dc:contributor.*- Author dc:creator
-
- Mohammed Abdul, Wasay
- Advisor dc:contributor.advisor
-
- Ahmed, Shibbir
- Committee members dc:contributor.committeemember
-
- Podorozhny, Rodion
- Chen, Xiao
Subjects
dc:subject × 7Rights
- Language dc:language.iso
- en
Identifiers
dc:identifier.*- Dc Identifier Citation
- Mohammed Abdul, W. (2025). Towards characterizing machine learning contracts using large language models. [Master's thesis, Texas State University].