KatInterview

Build a Log Structuring Pipeline with LLM-Generated Parsers

Machine LearningModel answer
MediumModel answerMachine Learningml-systemsdata-pipelinesparsing

Last updated

Design a scalable system that transforms unstructured log lines into structured JSON using LLM-generated regex parsers cached for high-volume processing.

You need to build a production system that converts raw, unstructured log messages from diverse sources into structured JSON records. The logs come in many different formats with varying schemas.

Your system should handle situations like these:

Web server log:

192.168.1.1 - - [10/Oct/2023:13:55:36 +0000] "GET /index.html HTTP/1.1" 200 1024 "http://example.com/start.html" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"

Should produce:

{
 "src_ip": "192.168.1.1",
 "time": "10/Oct/2023:13:55:36 +0000",
 "http_method": "GET",
 "path": "/index.html",
 "protocol": "HTTP/1.1",
 "response_code": 200,
 "duration": 1024,
 "url": "http://example.com/start.html",
 "userAgent": "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"
}

Application error log:

[Tue Oct 10 13:55:36 2023] [error] [pid 12345] [client 192.168.1.1:12345] File does not exist: /var/www/html/favicon.ico

Should produce a different schema with fields like timestamp, level, pid, client_ip, client_port, and error_message.

Design the complete system covering:

  • Overall architecture and data flow
  • How to identify and handle different log formats
  • Extraction approach and when to use LLMs versus other techniques
  • Schema discovery and field naming consistency
  • Validation and quality assurance
  • Scaling to high throughput
  • Reliability and failure handling
  • Monitoring and operational concerns
  • Privacy and security considerations

Hints

Hint 1

Calling an LLM for every log line at scale would be prohibitively expensive and slow—think about how to keep LLMs off the critical path

Hint 2

Most production logs follow a small number of repeating patterns; exploit this property

Hint 3

Deterministic parsers like regex are orders of magnitude faster than LLM calls once you have them