In the last section, we successfully set up a trigger, the essential starting gun for our workflow. We've essentially told Google Workspace Studio, "Hey, pay attention! A new email just arrived that matches our criteria." This is a crucial first step, but it's only half the story. The trigger hands our workflow a bundle of raw data—the entire email—and now we face the most common challenge in automation: the information we actually need is buried inside a block of unstructured, conversational text.
This is where the real power of modern workflow automation shines. We don't just want the whole email; we want specific pieces of information from it, like a customer's name, an order number, or a company name. Our Google Sheet needs clean, organized data in columns, not a messy paragraph. How do we bridge this gap? This is the AI step.
Step 2 (The AI Step): Extracting Key Information from the Email Body
The core task here is to transform unstructured data (the free-form text of an email) into structured data (a predictable format with clearly defined fields). Before tools like Workspace Studio, this required complex scripts, fragile text-parsing rules, or tedious manual copy-pasting. Now, we can achieve this by simply describing what we want to an AI model in plain English.
This process is called data extraction, and we'll accomplish it by writing a 'prompt'. A prompt is a set of instructions you give to the AI model. Think of it as briefing a highly intelligent but very literal assistant. The quality of your instructions directly determines the quality of the result.
Let's use our example of logging new sales leads. An email might arrive saying, "Hello, my name is Jane Doe and I work at Example Corp. I'd love to get a quote. You can reach me at jane.d@examplecorp.com." For our spreadsheet, we need three distinct pieces of data: "Jane Doe", "Example Corp", and "jane.d@examplecorp.com".
A well-structured prompt for this kind of data extraction typically has three parts:
-
Context & Role: Tell the AI what it is and what kind of data it's handling. For example, "You are an assistant processing a new sales lead from an email body."
-
The Task: Be explicit about what you want it to find. "Extract the full name, the company name, and the email address of the person."
-
Output Format Specification: This is the most critical part for automation. You must tell the AI exactly how to present the extracted information. The best practice is to request the output in JSON (JavaScript Object Notation), a universal standard for structured data. This ensures the output is predictable and easy for the next steps in our workflow to use.
Here is a practical example of what a complete prompt would look like inside the AI action in Workspace Studio. The {{trigger.body}} is a special placeholder, known as a variable, that Workspace Studio will automatically replace with the actual body of the email that triggered the workflow.
From the email content provided below, extract the contact's full name, their company name, and their email address.
Return the information ONLY in a valid JSON format. The JSON object should have three keys: "contactName", "companyName", and "contactEmail".
If any piece of information cannot be found, use a null value for its key. Do not add any explanation or text outside of the JSON object.
Email content:
{{trigger.body}}By using a prompt like this, you're instructing the AI to read the email, identify the key data points, and then package them neatly into a JSON object like {"contactName": "Jane Doe", "companyName": "Example Corp", "contactEmail": "jane.d@examplecorp.com"}. This structured output is a perfect, machine-readable package.
This AI-powered approach is incredibly robust. It can handle variations in phrasing—whether the person says "I work at," "I'm with," or "my company is"—far better than rigid rule-based systems. You've effectively delegated the messy task of understanding human language to the AI.
We have now successfully defined the second major step of our workflow. We've taken the raw data from our trigger and used an AI prompt to transform it into clean, structured, and predictable information. The obvious next question is how to get this perfectly formatted JSON data into the right columns of our Google Sheet. That's precisely what we'll cover in the next section, where we configure the final action of our workflow.
References
- Brown, T. B., et al. (2020). Language Models are Few-Shot Learners. arXiv:2005.14165.
- Google. (2024). Introduction to prompt design. Google AI for Developers.
- Eloundou, T., et al. (2023). GPTs are GPTs: An Early Look at the Labor Market Impact Potential of Large Language Models. OpenAI. arXiv:2303.10130.
- White, J., Fu, Q., Hays, S., et al. (2023). A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT. arXiv:2302.11382.
- Jurafsky, D., & Martin, J. H. (2023). Speech and Language Processing (3rd ed.). Prentice Hall. (For foundational concepts in NLP).