Abstract
Large-Language Models (LLMs) have shifted the paradigm of natural language data processing. However, their black-boxed and probabilistic characteristics can lead to potential risks in the quality of outputs in diverse LLM applications. Recent studies have tested Quality Attributes (QAs), such as robustness or fairness, of LLMs by generating adversarial input texts. However, existing studies have limited their coverage of QAs and tasks in LLMs and are difficult to extend. Additionally, these studies have only used one evaluation metric, Attack Success Rate (ASR), to assess the effectiveness of their approaches. We propose a MEtamorphic Testing for Analyzing LLMs (METAL) framework to address these issues by applying Metamorphic Testing (MT) techniques. This approach facilitates the systematic testing of LLM qualities by defining Metamorphic Relations (MRs), which serve as modularized evaluation metrics. The METAL framework can automatically generate hundreds of MRs from templates that cover various QAs and tasks. In addition, we introduced novel metrics that integrate the ASR method into the semantic qualities of text to assess the effectiveness of MRs accurately. Through the experiments conducted with three prominent LLMs, we have confirmed that the METAL framework effectively evaluates essential QAs on primary LLM tasks and reveals the quality risks in LLMs. Moreover, the newly proposed metrics can guide the optimal MRs for testing each task and suggest the most effective method for generating MRs.
Introduction: The Oracle Problem in LLM Evaluation
As Large Language Models (LLMs) become the backbone of modern software, their "black-box" nature presents a major challenge: how do we know they are actually reliable? Traditional software testing relies on "test oracles"—knowing the exact right answer for every input. However, for complex generative tasks like summarization or open-ended Q&A, a single "correct" answer often doesn't exist, and creating millions of labeled examples is prohibitively expensive.
Existing evaluation methods often suffer from a limited scope, focusing mostly on accuracy or a single type of robustness. Furthermore, they often rely on simplistic metrics like the Attack Success Rate (ASR), which fails to account for whether an adversarial input remains semantically valid or readable to a human.
The METAL Framework
The METAL (MEtamorphic Testing for Analyzing LLMs) framework addresses these challenges by shifting the focus from absolute correctness to relational consistency. Instead of checking if an output is "correct," METAL checks if the relationship between outputs of related inputs is "consistent."
The framework consists of two primary modules:
- Execution Module: This module handles the generation of perturbations. It uses 13 types of perturbations across character, word, and sentence levels (e.g., swapping characters, replacing synonyms, or adding demographic context). It then logs both the original and perturbed outputs from the LLM.
- Evaluation Module: This module applies Metamorphic Relations (MRs) to the logged data. These MRs serve as the "rules" of the test. For example, if a user's perceived gender is changed (fairness) or a typo is introduced (robustness), the model's sentiment analysis or classification should remain unchanged.
Metamorphic Relations and Metrics
A core innovation of METAL is the use of automated MR generation. By defining relations such as "Output A should equal Output B," the framework can generate hundreds of test cases automatically from a single unlabeled input.
Beyond standard metrics, the authors introduce the Effectiveness of MRs (EFM). They argue that ASR is a poor metric if a perturbation turns the text into gibberish; a model failing on unreadable noise is not necessarily a bug. EFM multiplies ASR by a "PerturbQuality" score based on semantic similarity, ensuring that the tests are meaningful and the perturbations maintain the original intent of the text.
Experimental Setup and Datasets
The researchers evaluated three industry-leading models: GooglePaLM (text-bison-001), ChatGPT (GPT-3.5-Turbo), and Llama2 (7b-chat). They sampled 900 input texts from diverse sources, including Amazon reviews (sentiment), news articles (classification/summarization), Kaggle toxicity datasets, and general web sources for Q&A and Information Retrieval (IR).
Key Results and Insights
The evaluation spanned six tasks and four Quality Attributes (Robustness, Fairness, Non-determinism, and Efficiency):
- Model Performance: GooglePaLM generally emerged as the top performer, demonstrating the highest robustness and fairness across most tasks. It also showed the most stability in inference time.
- Task Vulnerabilities: Classification tasks were generally more robust than generative tasks. Character-level swaps (like typos) were found to be devastating for classification, while word-level changes (like synonyms) were more effective at breaking generative tasks like summarization.
- Llama2's IR Struggles: A notable finding was Llama2's high non-determinism in Information Retrieval. When the model failed to understand a prompt, it often returned varying "canned" responses, leading to an ASR near 1.0, indicating it failed almost every perturbation test in that category.
- Fairness and Bias: All models exhibited some level of bias when demographic markers were introduced, though GooglePaLM remained the most consistent.
Conclusion and Future Directions
While METAL provides a systematic way to reveal hidden quality risks in LLMs without massive labeled datasets, the authors acknowledge several areas for future work. The current framework does not yet cover security (e.g., prompt injection), privacy, or explainability. Additionally, testing larger model variants (such as Llama2 70B) may yield different results. By providing an open-source framework, the authors aim to help engineers stress-test LLM-based applications before they reach production environments.
Summary updated