The Intern Who Only Spoke JSON
Picture this. You hire a new intern, Kevin. Kevin is… special. You can hand him a stack of 500 messy customer emails, rambling meeting notes, or chaotic support tickets. You ask him to fill out a spreadsheet with the key details: name, company, budget, and the core problem.
Kevin doesn’t complain. He doesn’t get tired. He doesn’t make typos. In three seconds, he hands you back a perfectly structured, perfectly formatted list of everything you asked for.
The only weird thing about Kevin? He communicates exclusively in JSON.
This isn’t a fantasy. Kevin is real. Except he’s not an intern, he’s an AI workflow. Today, I’m going to teach you how to build your own “Kevin” using the ridiculously fast Groq API. Get ready to fire your manual data entry department (or, more likely, free yourself from that soul-crushing work).
Why This Matters
Every business runs on data, but most of that data arrives as a chaotic mess. Emails, chat logs, call transcripts, resumes, invoices… it’s all unstructured text. The job of turning that mess into clean, usable information is one of the most expensive, boring, and error-prone tasks in any company.
This workflow replaces:
- Manual Data Entry: The hours you or your team spend copying info from one window and pasting it into another.
- Expensive Software: Specialized parsing tools that cost a fortune and only work for one document type (like invoices or resumes).
- Inconsistent Processes: When five different people extract data, you get five different results. This robot does it the same way, every single time.
We’re turning a manual, human-bottlenecked process into an infinitely scalable, instantaneous digital assembly line. This is a foundational skill for almost every serious automation you’ll ever build.
What This Tool / Workflow Actually Is
Let’s be clear. We are using the Groq API to run a Large Language Model (like Llama 3) with a very specific instruction: read a piece of text and output a JSON object containing the data we want.
What it is: A high-speed information extractor. It’s a specialized robot designed for one purpose: to read unstructured text and convert it into structured data (JSON) that other computer systems can immediately understand and use.
What it is NOT: This is not a general-purpose chatbot for your website. It’s not a creative writing assistant. It’s not magic. You have to tell it *exactly* what information to look for and what format to use. The magic is in its speed and its unwavering ability to follow instructions.
Prerequisites
I know the word “API” and “Python” might make some of you nervous. Don’t be. If you can copy and paste, you can do this. I promise.
- A GroqCloud Account: Go to GroqCloud and sign up. They have a generous free tier to get started. No credit card required.
- A Groq API Key: Once you’re in, find the “API Keys” section and create one. Copy it and save it somewhere safe. This is like a password for your automation.
- A place to run Python: We’ll use Google Colab. It’s a free online tool that lets you run code in your browser. No installation, no setup, no fuss. Just open a tab.
That’s it. You don’t need to be a programmer. You just need to follow my instructions.
Step-by-Step Tutorial
Let’s build our JSON-speaking intern.
Step 1: Set Up Your Workspace in Google Colab
Go to colab.research.google.com and click “New notebook”. This gives you a blank canvas to write and run your code.
Step 2: Install the Groq Library
In the first cell of your notebook, type this command and press the little “play” button (or Shift+Enter).
!pip install groq
This tells Google to install the necessary tools for our script to talk to Groq. It’s like downloading an app onto your phone.
Step 3: Securely Store Your API Key
In the next cell, we’ll import the libraries we need and set up our API key. Click the little key icon on the left sidebar of Colab, click “Add a new secret,” name it GROQ_API_KEY, and paste your key in as the value. Make sure the toggle is on to give this notebook access to it.
Now, in a new code cell, paste this:
import os
import json
from groq import Groq
from google.colab import userdata
# Get the API key from Colab's secret manager
GROQ_API_KEY = userdata.get('GROQ_API_KEY')
# Initialize the Groq client
client = Groq(
api_key=GROQ_API_KEY,
)
print("Groq client is ready!")
Run this cell. If it prints “Groq client is ready!”, you’re golden. You’ve successfully connected to the mothership.
Step 4: The Magic Prompt
This is where the real work happens. We need to tell the AI its job. The key is to be brutally specific. We will also use a special feature called “JSON Mode” that forces the AI to reply *only* in valid JSON.
Add a new code cell and paste this in. We’ll define some sample messy text and then create our request.
# Some messy, unstructured text from an imaginary email
unstructured_text = """
Hi there,
My name is Jessica Miller and I'm the operations manager at SwiftLogistics Inc. We're looking for a solution to automate our invoicing process. Our current budget is around $2,500/month. You can reach me at j.miller@swiftlogistics.com to schedule a demo.
Thanks,
Jess
"""
# The actual API call
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "You are an expert data extraction assistant. Your sole purpose is to extract structured data from the user's text. Output ONLY valid JSON. The schema should be: {\\\\"contact_name\\\\": string, \\\\"company_name\\\\": string, \\\\"email\\\\": string, \\\\"budget_per_month\\\\": integer, \\\\"summary\\\\": string}. If a value is not found, use null."
},
{
"role": "user",
"content": unstructured_text,
}
],
model="llama3-8b-8192",
# This is the magic part!
response_format={"type": "json_object"},
)
# Print the raw output
raw_output = chat_completion.choices[0].message.content
print("--- Raw Output ---")
print(raw_output)
# Print it as a nicely formatted dictionary
parsed_json = json.loads(raw_output)
print("\
--- Parsed JSON ---")
print(json.dumps(parsed_json, indent=2))
Let’s break that down:
unstructured_text: This is the raw material. It could be from an email, a form, anywhere.systemmessage: This is you telling the AI its job description. We are extremely clear: “You are an expert… output ONLY valid JSON… here is the exact schema.”usermessage: This is the actual text we want it to process.model: We’re using Llama 3’s 8B model. It’s fast and smart enough for this job.response_format={"type": "json_object"}: This is the secret weapon. It constrains the model, forcing it to return perfectly structured JSON, no excuses.
Run that cell. You’ll see the AI spit out exactly what we asked for.
Complete Automation Example
Let’s use a more complex, real-world example: processing messy meeting notes to update your CRM.
The Scenario
You just got off a call with a potential client. You frantically typed notes. Now you need to pull out the key details to create a new deal in your project management system.
The Input (Messy Notes)
meeting_notes = """
Meeting Notes - Project Phoenix - May 21st
Attendees: Me, Sarah from Acme Corp.
Her email is sarah.j@acmecorp.com. Phone number is 555-123-4567. They're looking to revamp their entire logistics system. Budget is a big question mark, but she mentioned something in the ballpark of $75k, maybe up to $90k if we can promise a Q3 delivery. Timeline is aggressive; they need a proof-of-concept by the end of July. Main pain point is their current system has very slow delivery tracking. Next steps: I need to send the full formal proposal by this Friday EOD. I should follow up with her on Monday if I don't hear back.
"""
The Automation Script
We use the exact same code as before, but we change the system prompt to ask for different fields, and we feed it our new `meeting_notes`.
# The API call for our meeting notes
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": "You are a CRM data entry assistant. Extract the following fields from the provided meeting notes and return them as a valid JSON object: {\\\\"contact_name\\\\": string, \\\\"company\\\\": string, \\\\"email\\\\": string, \\\\"phone\\\\": string, \\\\"estimated_budget\\\\": integer, \\\\"deadline\\\\": string, \\\\"pain_point\\\\": string, \\\\"next_action\\\\": string}. Use null for missing fields."
},
{
"role": "user",
"content": meeting_notes,
}
],
model="llama3-8b-8192",
response_format={"type": "json_object"},
)
# Parse and print the result
parsed_output = json.loads(chat_completion.choices[0].message.content)
print(json.dumps(parsed_output, indent=2))
The Perfect JSON Output
When you run this, you will get something beautiful and clean like this:
{
"contact_name": "Sarah",
"company": "Acme Corp.",
"email": "sarah.j@acmecorp.com",
"phone": "555-123-4567",
"estimated_budget": 90000,
"deadline": "End of July",
"pain_point": "Slow delivery tracking",
"next_action": "Send formal proposal by Friday EOD and follow up on Monday"
}
Look at that. Chaos turned into order. This JSON is now ready to be sent to any other application in your business.
Real Business Use Cases (MINIMUM 5)
This exact same pattern can be used everywhere.
- Business Type: E-commerce Store
Problem: Customers send vague emails about returns (“I need to return the blue shirt I bought last week”).
Automation: Read the email, extract `product_name`, `customer_name`, and `reason_for_return`, and use it to automatically find the order in Shopify and draft a return label email. - Business Type: Marketing Agency
Problem: Analyzing customer feedback from hundreds of survey responses to find trends.
Automation: Feed each open-ended survey response into the script. Extract `sentiment` (positive, negative, neutral), `key_topics` (e.g., pricing, support, features), and a one-sentence `summary`. - Business Type: Law Firm
Problem: Reviewing incoming case inquiry emails to see if they are a good fit for the firm.
Automation: Read the email, extract `case_type` (e.g., personal injury, family law), `potential_client_name`, and `summary_of_incident`. Use this data to route the lead to the correct paralegal. - Business Type: SaaS Company
Problem: Monitoring Twitter for mentions of your product to find bug reports.
Automation: When a new tweet mentions your brand, send the text to the script. Extract `is_bug_report` (true/false), `feature_mentioned`, and `user_handle`. If `is_bug_report` is true, automatically create a ticket in Jira. - Business Type: Financial Advisor
Problem: Transcribing client meetings and pulling out action items.
Automation: After a call is transcribed to text, this script reads the transcript and extracts a list of `action_items`, `deadlines`, and `person_responsible` for each item.
Common Mistakes & Gotchas
- Forgetting `response_format={“type”: “json_object”}`: This is the most common mistake. If you forget this, the AI might just give you a conversational answer instead of pure JSON, which will break your entire automation.
- A Vague System Prompt: Don’t say “Get the details.” Be a drill sergeant. Say “Extract these EXACT fields: `field_one`, `field_two`. The budget MUST be an integer. The email MUST be a string.” The more specific you are, the more reliable your output will be.
- Ignoring Missing Data: Your prompt should always tell the model what to do if it can’t find a piece of information (e.g., “use `null`” or “use an empty string `”`”). Otherwise, it might hallucinate an answer.
- Not Choosing the Right Model: For simple extraction, a fast model like `llama3-8b-8192` is perfect. For highly complex legal or medical documents, you might need a more powerful model. Start small and fast, then upgrade if needed.
How This Fits Into a Bigger Automation System
Think of this Groq workflow as one machine in a factory. It’s incredibly useful, but it needs an input conveyor belt and an output conveyor belt.
- Inputs (Where the text comes from):
- An automation tool like Zapier or Make.com can watch for a new email in Gmail, a new row in a Google Sheet, or a new entry from a Typeform, and then send the text to your script.
- A voice agent can transcribe a customer phone call and feed the text into this workflow to understand what the customer wanted.
- Outputs (Where the JSON goes):
- The structured JSON can be sent to your CRM (HubSpot, Salesforce) to create or update a contact.
- It can populate an email template to send a personalized follow-up.
- It can be stored in a database like Airtable or a SQL database to build a dashboard.
- It can be passed to the *next* AI agent in a multi-agent workflow. For example, one agent extracts the data, and a second agent uses that data to decide which sales playbook to run.
This is the engine of intelligence. It creates the structured fuel that powers all your other automations.
What to Learn Next
Congratulations. You’ve officially built a superhuman data entry intern. You can now turn any unstructured text into clean, predictable, and usable JSON at the speed of light.
You’ve created the organized pile of LEGO bricks. But a pile of bricks isn’t a castle.
In our next lesson in the Academy, we’re going to build the rest of the factory. We’ll take the perfect JSON output from this Groq workflow and use a tool like Zapier Webhooks to automatically create a new deal in our CRM, assign a task in Asana, and draft a follow-up email in Gmail — all triggered by our script, running in under a second.
You’ve mastered the ‘thinking’ part. Next, we learn how to make our automations *act* on that thinking in the real world. This is where it gets really powerful.
See you in the next lesson.
“,
“seo_tags”: “groq, groq api, structured data extraction, json, ai automation, python, llama 3, large language models, business automation, no-code”,
“suggested_category”: “AI Automation Courses

