First Steps with Google Workspace Studio: AI Workflow Development Course Connecting Gmail, Calendar and Spreadsheets

Crafting Effective Prompts for Clear and Concise Email Summaries

While the previous section armed you with the code to connect to Google's powerful AI models, simply making the connection is only half the battle. The true power—and the real magic—of your automated workflow lies not in the generativeAI.generateContent() call itself, but in what you ask it to do. This is the art and science of prompt engineering, and mastering it is the difference between an AI assistant that's vaguely helpful and one that becomes indispensable.

Think about it. A generic prompt like "summarize this email" might return a dry, one-sentence overview that misses the entire point. It might tell you "John sent an email about the Q3 project update," but it won't tell you that the project is blocked, a key deadline is at risk, and John needs your approval by end-of-day. We’re not just looking for a shorter version of the email; we’re looking for actionable intelligence. This section will teach you how to craft prompts that deliver exactly that: clear, concise, and context-aware summaries.

The core principle is to stop treating the AI like a search box and start treating it like a new team member you are training. A good prompt provides three critical elements: Role, Context, and Format. Giving the AI a specific Role tells it how to think. Providing Context gives it the necessary information to work with. And defining the Format dictates exactly how you want the information presented back to you, making it predictable and easy to process in your script.

Let’s look at a typical “before” scenario. A project manager wants to quickly understand a long email thread from a client. A beginner's attempt at a prompt might look like this:

Summarize this email thread for me:

---
{email_body_variable}
---

The result will likely be a generic paragraph. It’s better than nothing, but it's not a workflow accelerator. Now, let’s apply our framework to craft a much more effective prompt for the same task.

You are an expert project management assistant. Your task is to analyze an email from a client and extract only the most critical information for the project manager.

Here is the email thread:
---
{email_body_variable}
---

Analyze the email and provide a summary in a structured JSON format. The JSON object must have the following keys:
- "sentiment": (string) Classify the client's overall sentiment as 'Positive', 'Neutral', or 'Negative'.
- "key_takeaways": (array of strings) A list of the 2-3 most important points or decisions in the email.
- "action_items": (array of strings) A list of explicit tasks or questions directed at our team. If there are no action items, return an empty array [].

See the difference? We didn't just ask for a summary; we gave the AI a job. The Role is an “expert project management assistant,” which primes the model to focus on project-relevant details. The Context is the email body, clearly delineated. Most importantly, the Format is a specific JSON structure. This is a game-changer for automation, as your Google Apps Script can now reliably parse this output using JSON.parse() and use the data to update a spreadsheet, create a calendar event, or even draft a reply.

チャプターへ戻る