← Lab /AI/ML

LLMs generate high-accuracy code snippets for CAPEC and CWE vulnerabilities

LLM-generated code snippets accurately reflect CAPEC/CWE vulnerability descriptions

AI/ML arXiv 2 Apr 2026 Benchmark Prototype evidence

Published as “From Theory to Practice: Code Generation Using LLMs for CAPEC and CWE Frameworks”

Why it matters

The dataset can be used to teach secure coding, train vulnerability detection models, and aid security researchers in understanding real-world exploit patterns.

Summary

The authors show that GPT-4o can automatically generate vulnerable code examples for every CAPEC entry in Java, JavaScript, and Python, with about 90% of the snippets compiling, 100% relevance to the CAPEC descriptions according to evaluators, and high readability (Python scoring 4-5). Manual evaluation of 30 random snippets per language yielded inter-rater agreement above 93% and CodeBERT similarity scores above 0.98, indicating consistent outputs. Evidence is based on a limited manual sample and similarity metrics, not on large-scale automated testing.

What they found 4

  1. Approximately 90% of generated snippets compile successfully.

    “The results show that approximately 90% of the code snippets compiled successfully across most datasets, with Python exhibiting the highest compilation success rate, followed by Java and then JavaScript.”

  2. All evaluated snippets were judged relevant to their CAPEC descriptions.

    “three of the evaluators agree that 100% of the code snippets are relevant to the CAPEC descriptions.”

  3. Python snippets received the highest readability scores (4-5).

    “the code generated in Python was rated as the most readable, consistently achieving higher scores compared to Java and JavaScript.”

  4. Generated code shows high similarity across datasets (cosine similarity >0.98).

    “Java and Python exceed a cosine similarity of 0.99, while JavaScript achieves over 0.98.”

Caveats 1

  • Only about 90% of the snippets compiled, meaning roughly 10% failed to compile.

What’s new here 4

  • Provides a comprehensive code dataset covering all CAPEC entries across three major programming languages.
  • Uses GPT-4o with tailored prompts via LangChain to generate the examples.
  • Evaluates generated code for compilability, relevance, readability, and cross-model consistency using manual reviews and CodeBERT similarity.
  • Compares consistency of GPT-4o outputs with those of Llama and Claude.