Skip to content

06 · TK-101 · Projects

LLM prototype for assessing drinking-water quality

A Python program that sends pH, total dissolved solids (TDS), turbidity and temperature to Gemini with a water-filtration expert prompt and worked examples, and gets back a JSON verdict: drinkable or not, a percentage, the problem and recommendations. An early experiment before the graduation project.

Illustration: water-quality readings going into an LLM and coming out as a JSON verdict
Stack
PythonGemini 1.5 Flashgoogle-generativeaiJSON outputpandasFine-tuning trial

The problem

Water-quality sensors give numbers, but a tank or plant owner wants an answer: is the water safe to drink, what is wrong if not, and what to do. Turning numbers into a clear decision is what this prototype tried.

Solution and data flow

  • Instructions: the model is cast as a water-filtration expert and asked for JSON with four fixed fields: drinkable, drinkability_percentage, problem and recommendations.
  • Worked examples: the chat opens with short questions and answers on how TDS, pH, turbidity and temperature affect potability in numbers, so the verdict rests on clear limits (such as pH 6.5 to 8.5 and turbidity under 1 NTU).
  • Test loop: random readings in a sensible range are generated every 10 seconds, sent, and the reply is parsed into tidy JSON, or the parse failure is logged.
  • Fine-tuning trial: a separate attempt to train a tuned Gemini model on a 10,000-row sample of a public water-quality dataset, with pH, TDS, turbidity and potability columns.

Implementation and challenges

Forcing JSON through response_mime_type made the reply machine-readable, but a high generation temperature means two close readings can get different verdicts, which is why a final decision should rest on fixed limits and not on the model alone. The work stayed a prototype on generated readings rather than real sensors; the same idea (readings into an LLM, diagnosis and advice out) later grew into the predictive-maintenance graduation project.

Skills developed

Prompt engineering, forcing JSON output, in-context examples, data preparation with pandas, and a fine-tuning trial on an LLM.