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.
As you build your own AI-powered workflows, keep these rules of thumb for writing effective prompts in mind:
Be Specific and Explicit: Vague requests lead to vague answers. Instead of "What's the main point?", ask "What is the primary question the sender is asking?"
Define the Output Structure: Always tell the model how you want the information back. JSON, Markdown lists, or even a simple bulleted list are far more useful for scripting than a plain paragraph.
Provide Examples (Few-Shot Prompting): For more complex tasks, you can include a small example of the input and desired output directly in your prompt. This technique, known as few-shot prompting, dramatically improves accuracy for nuanced tasks.
Iterate and Refine: Your first prompt won't be perfect. Test it with different kinds of emails. If the summary isn't quite right, adjust the prompt—clarify the role, add more constraints to the format, or be more explicit about what to ignore.
By mastering the craft of writing prompts, you move from being a simple user of AI to being a true architect of an intelligent system. The prompt is your primary lever for controlling the quality and utility of your AI-driven results. Now that you know how to get a consistently structured summary from any given email, a new question arises: how do you build a system that can handle different types of emails automatically? In the next section, we’ll explore how to use AI not just for summarization, but for categorization, turning your inbox into a self-organizing data source.
References
- Brown, T. B., et al. (2020). Language Models are Few-Shot Learners. arXiv:2005.14165.
- White, J., & Nalog, A. (2023). A Prompt Engineering Guide. GitHub. Retrieved from github.com/dair-ai/Prompt-Engineering-Guide.
- OpenAI. (2023). Best practices for prompt engineering with OpenAI API. Retrieved from help.openai.com.
- Anthropic. (2024). Introduction to prompt design. Retrieved from docs.anthropic.com/claude/docs/introduction-to-prompt-design.
- Eloundou, T., et al. (2023). GPTs are GPTs: An Early Look at the Labor Market Impact Potential of Large Language Models. arXiv:2303.10130.