Having explored the foundational principles of prompt engineering in the previous section, you now possess the key to unlocking a conversation with a large language model. You know how to ask for a summary, change the tone, and ask follow-up questions. But what if your goal isn't just to understand a single piece of information, but to organize hundreds or thousands of them automatically? This is where we move beyond summarization and into classification.
Imagine your inbox is flooded with customer inquiries, project updates, and automated alerts. A summary of each is helpful, but it doesn't solve the bigger problem: your inbox is still an unstructured list of messages. To truly build an intelligent workflow, you need to automatically sort this information into meaningful buckets. This is the power of AI-driven data categorization—transforming a chaotic stream of text into a neatly organized dataset in your Google Sheet, ready for analysis, action, and automation.
This process is conceptually simple but incredibly powerful. Instead of asking the AI to just tell you what an email is about, you'll instruct it to act as a highly-trained sorting assistant. You provide the email content and a predefined list of categories, and the AI's job is to return only the single most appropriate category from that list. This simple act of assigning a label is the first step in creating structured data from unstructured text.
Let's consider a practical scenario. A small business uses a generic email address for customer support. In a single day, they might receive emails that are:
- A request for a refund.
- A question about product features.
- A report of a bug on their website.
- Positive feedback from a happy customer.
- An inquiry about job openings.
Manually reading and tagging each one is a full-time job. With our workflow, we can teach the AI to do it instantly. The first and most critical step is defining our categories. They should be clear, concise, and mutually exclusive to avoid ambiguity.
For our example, a good set of categories would be:
Sales InquiryTechnical SupportBilling IssueCustomer FeedbackCareer Opportunity
With our categories defined, we can now craft a specific prompt for classification. This is a direct application of the prompt engineering skills you've been developing. A good classification prompt clearly states the task, provides the text to be analyzed, and, most importantly, lists the exact categories the model is allowed to choose from.
Here’s how you might structure such a prompt within your Google Apps Script code:
function getCategorizationPrompt(emailBody, categories) {
const categoryList = categories.join(', ');
return `
Analyze the following email text and classify it into ONE of the following categories: ${categoryList}.
Only return the single category name and nothing else.
Email Text:
"""
${emailBody}
"""
Category:
`;
}Notice the key instructions: "classify it into ONE," "Only return the single category name," and providing the list explicitly. This tight constraint is crucial for getting clean, predictable data that you can easily use in a Google Sheet column. Without it, the model might get creative and return something like "Question about Sales," which would break your downstream automation.
graph TD
A[New Email in Gmail] --> B{Google Workspace Studio Trigger};
B --> C[Run AI Summary Function];
B --> D[Run AI Categorization Function];
C --> E{Write to Google Sheet};
D --> E;
E --> F[Column A: Summary];
E --> G[Column B: Category];
This simple workflow diagram shows how categorization fits right alongside the summarization task we've already discussed. For every new email, your system not only understands its essence but also files it under the correct label. Suddenly, your Google Sheet isn't just a log; it's a dynamic database. You can filter by Billing Issue to prioritize financial tasks or review all Customer Feedback at the end of the week.
You've now unlocked a fundamental technique for building sophisticated AI workflows. By converting free-form text into clean, consistent labels, you're paving the way for more advanced data analysis, automated responses, and intelligent reporting—all powered by the tools within Google Workspace.
But what if a single category isn't enough? Many emails contain multiple pieces of valuable information. An email categorized as a Billing Issue might also contain a new shipping address and a contact phone number. In the next section, we'll level up again and explore AI-driven data extraction to pull these specific details out of the text and into their own dedicated columns.
References
- Kowsari, K., et al. (2019). Text Classification Algorithms: A Survey. Information, 10(4), 150.
- Google Cloud. (2024). Classification using large language models. Retrieved from cloud.google.com/vertex-ai/docs/generative-ai/text/classification-prompts.
- Minaee, S., et al. (2021). Deep Learning based Text Classification: A Comprehensive Review. arXiv:2004.03705.
- Jurafsky, D., & Martin, J. H. (2023). Speech and Language Processing (3rd ed. draft). Chapter on Text Classification and Naive Bayes.
- Raffel, C., et al. (2020). Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer. Journal of Machine Learning Research, 21(140), 1-67.