Skip to main content
Welcome back — in this lesson/article we’ll build a minimal personal-trainer assistant that:
  • ingests fitness data from CSV using pandas,
  • collects user fitness goals interactively,
  • composes a chat message sequence (system, assistant, user),
  • calls a language model to generate role-specific, actionable recommendations.
A presentation slide titled "Project 04 – Personal Trainer" with a large turquoise "Demo" label on a dark curved shape at the right. The layout is minimal with a light background and a small "© Copyright KodeKloud" notice in the bottom-left.

What we’ll build

  • Load a CSV into a pandas DataFrame and summarize it.
  • Collect user goals into a goals list.
  • Build a trainer function that assembles chat messages (user goals + system/assistant context) and calls the model.
  • Refine the assistant prompt to return direct, role-aware, point-form recommendations.

Prerequisites

Install pandas if you don’t have it:
Also ensure you have your OpenAI (or other) client library installed and configured. Replace "YOUR_API_KEY" in the example with a secure retrieval method (e.g., environment variable).

Minimal, complete example

The script below demonstrates a compact implementation. It:
  • reads a CSV into a DataFrame,
  • gathers goals interactively,
  • builds the chat messages list,
  • sends the request to the model and prints the response.
Note: keep DataFrame summaries concise — don’t send full datasets directly to the model.

How the message sequence works

The assistant receives three kinds of messages: This ordering ensures the model sees the user goals plus clear, role-specific context and a compact data snapshot.

Typical interactive run (example)

Example model output (trimmed and formatted)

Prompt refinement tips

  • Be explicit about role and required output style (e.g., “The person is an accountant. Respond: Direct. Point form.”).
  • Avoid including large raw datasets in prompts. Instead:
    • Send df.head().to_string() or df.describe() snippets,
    • Or extract key columns and aggregate statistics.
  • If you need repeated or more detailed data analysis, run offline analysis with pandas and provide only the relevant derived metrics to the model.
Avoid sending very large raw datasets directly in prompts. Summarize or extract key columns/rows to keep prompts concise and within token limits.

Best practices and security

  • Store API keys securely (environment variables, secrets managers).
  • Sanitize any sensitive user data before sending to remote APIs.
  • Use conservative temperature settings for reproducible, factual recommendations when needed.
  • Log prompts and model outputs carefully, respecting privacy and compliance requirements.
And that’s it — by combining compact data summaries, a clear role-aware assistant prompt, and a simple interactive goal collection, you can generate focused, actionable personal-training recommendations.

Watch Video