Skip to main content

Claude/ChatGPT Prompt to Automate a Daily Report Email with Pandas

Prompt for a cron-friendly Python script that pulls data, computes KPIs in Pandas, renders inline charts, and emails an HTML report via SMTP.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt casts the model as a senior Python data engineer and asks for a cron-friendly script that runs daily and emails a KPI report, returning complete runnable code rather than pseudocode. It lays out six deliverables: a query/extract step that pulls the window implied by the schedule with a clear date boundary, KPI computation in Pandas with day-over-day deltas, matplotlib charts rendered to PNG and embedded inline via CID plus an HTML summary table, an SMTP send with TLS, a plaintext fallback part, and retry on transient failure, all secrets and config via environment variables with a sample .env, and structured logging with a non-zero exit code on failure for cron alerting. The structure works because it makes the job fail loudly, which is what makes a daily email a trustworthy monitor.

Four variables drive it. [data_source] names where data comes from, like a PostgreSQL events table. [kpis] lists the metrics to compute — DAU, WAU, conversion rate, revenue — each getting a day-over-day delta. [recipients] sets who receives the email. [schedule] defines cadence and window, such as daily at 07:00 covering yesterday, which drives the date boundary in the extract step. Deliverable six is the load-bearing part: a silent broken cron is worse than no report, so the script must exit non-zero on failure so the scheduler can alert.

When to use it

  • A stakeholder wants daily numbers in their inbox without building a full dashboard.
  • You need a cron-friendly script that pulls data, computes KPIs, and emails a report.
  • Day-over-day deltas and inline charts matter for the report's readability.
  • You want secrets handled via environment variables with a documented sample .env.
  • Failure must be loud — a non-zero exit code so a broken cron job alerts you.
  • You need the full script plus the crontab line to schedule it.

Example output

Expect the full script plus the crontab line to schedule it. An extract step pulls the window implied by [schedule] with a clear date boundary from [data_source]; Pandas computes [kpis] with day-over-day deltas; matplotlib renders charts to PNG embedded inline via CID alongside an HTML summary table; an SMTP send to [recipients] uses TLS with a plaintext fallback and retry on transient failure; config flows through environment variables documented in a sample .env; and structured logging plus a non-zero exit on failure enables cron alerting. It is complete, runnable code you adapt to your environment.

Pro tips

  • Be specific in [data_source] (table or query) so the extract step targets the right data with a correct date boundary.
  • List [kpis] precisely; each one gets a day-over-day delta, so vague metrics produce vague computations.
  • Align [schedule] cadence and window carefully, since it drives the date boundary the extract uses.
  • Make the job fail loudly with a non-zero exit; a silent broken cron is worse than no report at all.
  • Keep all secrets in environment variables per the sample .env rather than hardcoding SMTP credentials.
  • If charts render poorly, re-run asking for specific chart types per KPI and inline CID embedding details.

Frequently Asked Questions

Why does the script need a non-zero exit code?
A silent broken cron is worse than no report, so the script exits non-zero on failure to let the scheduler alert you. Combined with structured logging, this ensures you hear about a broken daily report instead of quietly missing it.
Can I choose which KPIs the report computes?
Yes. The `[kpis]` variable lists the metrics, defaulting to DAU, WAU, conversion rate, and revenue, and each gets a day-over-day delta. List them precisely, since vague metric names produce vague Pandas computations.
How are the charts included in the email?
matplotlib renders charts to PNG and embeds them inline using CID references, alongside an HTML summary table. The SMTP send also includes a plaintext fallback part so clients that block images still receive a readable report.
How are database and SMTP credentials handled?
All secrets and config flow through environment variables, documented in a sample .env file. The data source itself is set via `[data_source]`, so you keep credentials out of the script and configure each environment separately.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Python & Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support