Log Parsing with Self-Generated In-Context Learning and Self-Correction

Yifan Wu, Siyu Yu, Ying Li · DOI

Abstract

AdaParser is a novel log parsing framework that leverages Large Language Models (LLMs) to transform unstructured system logs into structured templates. By employing a self-generated in-context learning (SG-ICL) approach and an automated self-correction loop, AdaParser achieves state-of-the-art accuracy on evolving log data without requiring historical training data. It maintains the efficiency of traditional rule-based parsers through a hybrid architecture that combines deterministic tree-based matching with generative AI.

Introduction

Log parsing is a critical first step in system observability, transforming raw, unstructured strings into structured templates and variables. For instance, a raw log entry like 17/08/22 15:51:02 INFO BlockManager Writing block rdd_1_3 to disk is decomposed into a static template (Writing block <*> to disk) and a dynamic variable (rdd_1_3). This structured data is essential for downstream tasks like anomaly detection and root cause analysis.

The process of log generation and parsing into structured formats.

However, modern software evolution poses significant challenges. Traditional syntax-based parsers rely on rigid rules that break when log formats change, while semantic-based deep learning models require frequent, expensive retraining. Large Language Models (LLMs) offer strong semantic understanding but suffer from two main flaws: hallucinations—often abstracting critical keywords into wildcards—and a heavy dependency on extensive historical examples for In-Context Learning (ICL).

Methodology: The AdaParser Framework

AdaParser addresses these issues through a three-stage pipeline designed to balance efficiency with adaptability.

The three-stage architecture of AdaParser, including the Tree-based Parser, SG-ICL-based Parser, and Template Corrector.

1. Tree-based Parser

To maintain high throughput and avoid expensive LLM calls for every log entry, AdaParser first attempts to match incoming logs against a "trie" (prefix tree) of previously identified templates. If a match is found, the log is parsed instantly. This component handles the vast majority of logs in stable systems.

2. Self-Generated In-Context Learning (SG-ICL)

When the tree-based search fails to find a match, the system invokes the LLM. Unlike standard ICL which requires a static set of human-labeled examples, AdaParser maintains a dynamic candidate set of its own successful previous parses. Using a k-Nearest Neighbors (kNN) approach, it selects the most relevant previous parses to serve as demonstrations in the prompt. This allows the model to "learn on the job" and adapt to new log formats without prior training data.

3. Template Corrector

To ensure structural integrity, AdaParser employs a self-correction loop with two primary strategies:

  • Template Matching Correction: The generated template is converted into a regular expression. If the original log does not match this regex, the LLM is prompted to revise its output.
  • Variable Abstracting Correction: The system checks if the LLM has erroneously turned important keywords (e.g., failed, IOException) into wildcards. If such "over-abstraction" is detected, the LLM is instructed to preserve these keywords in the static template.

Evaluation and Results

The framework was evaluated using Loghub-2.0, a comprehensive benchmark of 14 datasets (including Hadoop, Spark, and Zookeeper) totaling over 50 million log messages.

Accuracy and Adaptability

AdaParser achieved a 96.3% Grouping Accuracy and 87.9% Template Accuracy, outperforming established baselines like Drain, LogPPT, and LILAC. Its strength is most apparent in zero-shot scenarios (0% historical data), where it surpassed the previous best LLM-based parser, LILAC, by 29.1% in Parsing Accuracy and 44.9% in Template Accuracy.

Efficiency and Cost

By offloading approximately 99% of parsing tasks to the Tree-based component, AdaParser processed 3.6 million logs in 550 seconds—comparable to the lightning-fast rule-based Drain parser (447s). Furthermore, using GPT-3.5-turbo, the total cost for these 3.6 million logs was only $0.75, demonstrating that LLM-based parsing is economically viable for production environments.

Conclusion

AdaParser demonstrates that LLMs can be effectively integrated into high-speed system monitoring pipelines. By combining the deterministic speed of trie-based matching with the semantic flexibility of self-correcting LLMs, it provides a robust solution for parsing evolving logs in real-time. Future work will focus on enhancing privacy through local deployment of open-source models and further tuning the self-correction feedback loop to optimize accuracy across diverse system architectures.

Summary updated

BibTeX
@inproceedings{wu2025log,
  author = {Yifan Wu and Siyu Yu and Ying Li},
  title = {{Log Parsing with Self-Generated In-Context Learning and Self-Correction}},
  booktitle = {ICPC},
  year = {2025},
  url = {https://openreview.net/forum?id=Cjak89nzLN},
}
Figure