From Dirty Application Logs to AI Analysis with Python on Raspberry Pi

We'll start with another dirty application-log dataset, clean it with Pandas, and then send the cleaned records to an AI model for an evaluation of what is happening in the application.

 

From Dirty Application Logs to AI Analysis with Python on Raspberry Pi

In our last example, Python and Pandas turned messy application-log data into clean CSV and JSON files.

This time we'll take the idea one step further.

We'll start with another dirty application-log dataset, clean it with Pandas, save the results for both people and software, and then send the cleaned records to an AI model for an evaluation of what is happening in the application.

The pipeline becomes:

dirty JSON → Pandas → clean data → CSV + JSON → AI API → evaluation

The AI isn't being asked to clean our application logs.

That's deliberate.

Python handles the predictable data-cleaning work first. Only then do we give the clean records to a model and ask it to interpret what they appear to show.

Another Messy Application Log

Create application_log_ai.json:

[
  {
    "timestamp": "2026-11-03 14:00:00",
    "service": "orders",
    "status": "SUCCESS",
    "response_ms": 176
  },
  {
    "timestamp": "2026-11-03 14:05:00",
    "service": " Orders ",
    "status": "success",
    "response_ms": 193
  },
  {
    "timestamp": "2026-11-03 14:10:00",
    "service": "payments",
    "status": "ERROR",
    "response_ms": 864
  },
  {
    "timestamp": "2026-11-03 14:15:00",
    "service": "PAYMENTS",
    "status": "error",
    "response_ms": "1126"
  },
  {
    "timestamp": "wrong_time",
    "service": "orders",
    "status": "success",
    "response_ms": 205
  },
  {
    "timestamp": "2026-11-03 14:25:00",
    "service": "payments",
    "status": "SUCCESS",
    "response_ms": 238
  },
  {
    "timestamp": "2026-11-03 14:25:00",
    "service": "payments",
    "status": "SUCCESS",
    "response_ms": 238
  },
  {
    "timestamp": "2026-11-03 14:30:00",
    "service": "orders",
    "status": "success",
    "response_ms": null
  }
]

Again, the problems are obvious once we look at the file.

Service names and status values use inconsistent capitalization. One service name contains extra spaces. One response time is stored as text rather than a number. One timestamp is invalid. Another response time is missing. And one log entry appears twice.

The JSON itself is valid.

The data inside it needs cleaning.

Cleaning the Application Log

We'll use Pandas again:

import pandas as pd

# INPUT
df = pd.read_json("application_log_ai.json")

# PROCESSING

# Convert timestamps into datetime values
df["timestamp"] = pd.to_datetime(
    df["timestamp"],
    errors="coerce"
)

# Remove extra spaces and normalize text
df["service"] = (
    df["service"]
    .str.strip()
    .str.lower()
)

df["status"] = (
    df["status"]
    .str.strip()
    .str.lower()
)

# Convert response times to numeric values
df["response_ms"] = pd.to_numeric(
    df["response_ms"],
    errors="coerce"
)

# Remove records with invalid or missing values
df = df.dropna(
    subset=["timestamp", "service", "status", "response_ms"]
)

# Remove duplicate log entries
df = df.drop_duplicates()

# Put the log entries in time order
df = df.sort_values("timestamp")

# Reset row numbers
df = df.reset_index(drop=True)

# OUTPUT
df.to_csv(
    "application_log_ai_clean.csv",
    index=False
)

df.to_json(
    "application_log_ai_clean.json",
    orient="records",
    date_format="iso",
    indent=2
)

print(df)
print("\nCreated application_log_ai_clean.csv")
print("Created application_log_ai_clean.json")

Run it:

python3 clean_logs_ai.py

Once again we have the same basic pattern:

input → processing → output

Pandas reads the JSON file, cleans its contents according to our rules, removes unusable and duplicate records, and writes clean CSV and JSON versions.

But now we have another potential consumer.

An AI model.

Giving the Log Data to an AI Model

For this experiment we'll use OpenRouter's Free Models Router. openrouter/free selects from the free models currently available through OpenRouter and is intended for experimentation, learning, and low-volume use.

That distinction matters: openrouter/free isn't one fixed model. The router chooses an available free model for each request.

You'll need an API key. Rather than putting that key directly inside the Python program, set it as an environment variable:

export OPENROUTER_API_KEY="your-key-here"

We'll also need the Requests library:

python3 -m pip install requests

Now create analyze_logs.py:

import json
import os
import requests

API_KEY = os.environ["OPENROUTER_API_KEY"]

with open("application_log_ai_clean.json", "r") as file:
    log_data = json.load(file)

prompt = f"""
You are evaluating a small set of cleaned application-log records.

Briefly describe what is happening in the application.
Identify any noticeable patterns in response times and errors.
Point out anything that might deserve further investigation.

Do not invent causes or technical explanations that are not
supported by the supplied log data.

Application log:
{json.dumps(log_data, indent=2)}
"""

response = requests.post(
    "https://openrouter.ai/api/v1/responses",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json",
    },
    json={
        "model": "openrouter/free",
        "input": prompt,
    },
    timeout=60,
)

response.raise_for_status()

result = response.json()

message = next(
    item
    for item in reversed(result["output"])
    if item["type"] == "message"
)

analysis = next(
    part["text"]
    for part in message["content"]
    if part["type"] == "output_text"
)

evaluation = {
    "model": result["model"],
    "analysis": analysis
}

with open("application_log_ai_evaluation.json", "w") as file:
    json.dump(
        evaluation,
        file,
        indent=2
    )

print(analysis)
print("\nModel used:", result["model"])
print("Created application_log_ai_evaluation.json")

Run it:

python3 analyze_logs.py

This follows OpenRouter's Responses API pattern: the request goes to /api/v1/responses with a model and input, and the returned response contains the generated message.

Our program adds another step.

It saves the model's evaluation as a new JSON file.

Example AI Evaluation

A response might look something like this:

The application log shows successful requests with response times below 250 milliseconds alongside two payment-service errors with substantially higher response times of 864 and 1,126 milliseconds. The errors and higher response times appear together in the payment-service records in this small sample. That pattern may deserve further investigation, although the log data alone does not establish the cause.

The exact response will vary depending on which model is selected and how it interprets the records.

What's important is that the evaluation doesn't simply scroll past in the terminal.

Our Python program saves it as application_log_ai_evaluation.json.

Now the AI analysis is itself another data artifact.

Python Cleans. AI Evaluates.

There's an important architectural distinction inside this little Raspberry Pi project.

We didn't throw dirty application logs at an AI model and ask it to sort everything out.

We gave deterministic work to normal software.

Pandas validates the timestamps. Pandas converts response times into numbers. Pandas normalizes text. Pandas removes incomplete and duplicate records. Pandas writes the clean CSV and JSON files.

Only after that pipeline produces predictable input do we invoke an AI model for the less deterministic part:

What does this application log appear to tell us?

Our prompt asks the model to identify patterns in response times and errors while explicitly telling it not to invent causes that the log doesn't establish.

That division of labor is worth noticing.

Application logs record. Pandas cleans. Code validates. AI evaluates.

One Pipeline, Three Artifacts

This time the Raspberry Pi produces three useful artifacts.

application_log_ai_clean.csv contains the cleaned application-log records in a format convenient for Excel. A manager could filter the records, summarize errors, chart response times, and use those results when preparing reports or presentations in Excel, PowerPoint, or Word.

application_log_ai_clean.json contains the same cleaned underlying records in a structured form for developers and programs. It can be filtered, queried, sent to another API, or used as input to another software process.

application_log_ai_evaluation.json preserves the AI model's interpretation of those records.

That third artifact can be useful to both audiences.

A manager can use the evaluation alongside the underlying data when preparing an operational report. Developers or other programs can consume the evaluation JSON programmatically while retaining access to the cleaned log records that produced it.

The AI assessment doesn't replace the underlying data.

It travels alongside it.

Our complete pipeline now looks like this:

dirty application-log JSON → Python/Pandas → clean data → CSV for people + JSON for software → AI API → JSON evaluation

We started with messy machine-generated information and ended with three durable artifacts serving different purposes.

Traditional software did the predictable work.

AI handled the interpretation.

And the results are available to both people and programs.

That's a surprisingly complete data-and-AI pipeline to have running on a Raspberry Pi.



Copyright © 2026 Daily Tech-Reader.blog
All Rights Reserved

Popular posts from this blog

Insight: The Great Minimal OS Showdown—DietPi vs Raspberry Pi OS Lite

Troubleshooting Raspberry Pi Connect Issues: A Comprehensive Guide