Gemini Prompt Engineering for Data Enthusiasts

Leon Nicholls
7 min readMar 29, 2024

--

Ever wish you had a robot assistant who could organize messy data, process information, and even help with creative tasks that hurt your brain? Meet Google Gemini — it might be the amazingly versatile AI tool you’ve been looking for!

Get ready to meet your new friend — Gemini, the data transformation ninja!

Note: This article spotlights techniques for the Google Gemini Advanced chatbot (a paid service). While these concepts also apply to the free version, we’ll focus on the enhanced capabilities offered by the Advanced subscription.

Tame the Data Beast

Picture this: you’ve got a mountain of messy data. Different formats, typos everywhere, and data as useful as a chocolate teapot. Frustrating, right?

Why Clean Data Matters

Think of Gemini as a super-intelligent robot. You can ask it to do all sorts of amazing things, but give it a jumbled mess, and it’ll be just as confusing as you are. Clean, well-structured data is the key to getting accurate results, whether you’re analyzing sales figures or training Gemini to write you a poem (yes, it can do that, but more on creative stuff later!).

Gemini to the Rescue — Real-World Examples

Let’s get practical. Consider the following data:

Package                Version          Latest         Type
---------------------- ---------------- -------------- -----
absl-py 1.2.0 2.1.0 wheel
accelerate 0.21.0 0.28.0 wheel
aiohttp 3.8.1 3.9.3 wheel
aiosignal 1.2.0 1.3.1 wheel
albumentations 1.2.1 1.4.2 wheel
altair 4.2.0 5.2.0 wheel
antlr4-python3-runtime 4.9.3 4.13.1 wheel
anyio 3.6.1 4.3.0 wheel
argon2-cffi 21.3.0 23.1.0 wheel
asttokens 2.0.5 2.4.1 wheel
async-timeout 4.0.2 4.0.3 wheel
attrs 21.4.0 23.2.0 wheel

It lists useful software packages and versions, but it needs a makeover! Our first mission is to tell Gemini to ditch the version numbers and types, leaving us with a clean list of package names.

Ready for some prompt magic? Here’s how you’d ask Gemini:

Can you please remove the version numbers and type from this table and give me only the package names with a single space between each?

Gemini understands your request and works without you learning scripting or programming to filter the list.

Leveling Up: Ordering Your Data

Time to put Gemini’s sorting skills to the test! Check out this scrambled list:

Deliberation and verdict.
Witness testimonies and cross-examination.
Jury instruction.
Selecting a jury.
Closing arguments.
Opening statements.

With a carefully crafted prompt, Gemini can quickly put this in order. Here’s the kind of instruction you might give it:

Please put the following steps of a trial in the correct chronological order.

Extracting Specific Data

Sometimes, you must pull out particular information from a larger text. Imagine you’re planning a trip, and you’ve written down this itinerary:

“My whirlwind trip took me from SFO to ORD for a conference, then a quick hop over to MIA for beach time. I almost missed my connection in DFW — what a hectic airport!”

Let’s say you only want a list of the airport codes. Here’s how you’d instruct Gemini:

Your task is to review my text and identify any genuine airport codes mentioned. Present them as a list in the order they appear, adhering to official IATA or ICAO standards. Consider the surrounding text to improve the accuracy of identification. If no genuine airport codes are found, return an empty list.

Gemini will pick out airport codes for you!

Name Extraction

How about extracting names and professions from a text? Imagine this description:

“In the charming town of Oakwood Creek, a vibrant group of people shaped the community. There was Olivia Bennett, the town’s beloved veterinarian. William Parker was a skilled carpenter. Sofia Rodriguez, a passionate teacher, inspired young minds. And finally, there was Thomas Lee, the warmhearted chef.”

You could ask Gemini:

Make a list of the names and professions of the people in this town. Each name should be formatted like: First Name, Last Name [profession]

Data Transformation: Turning JSON into CSV

Data often comes in different formats. Gemini is awesome at converting one to another, saving you time. Let’s say you have this JSON data:

[
{
"name": "John Doe",
"age": 30,
"city": "New York",
"email": "john.doe@example.com"
},
{
"name": "Jane Smith",
"age": 25,
"city": "London",
"email": "jane.smith@example.com"
},
{
"name": "Bob Johnson",
"age": 35,
"city": "Paris",
"email": "bob.johnson@example.com"
}
]

And it would be best if you had it in a CSV spreadsheet. Here’s your prompt:

Please convert the following JSON data into a CSV file. Columns should be in the order: name, age, city, email. Use semicolons (;) as delimiters and enclose all values in double quotes (“).

Actionable Tips: The Do’s and Don’ts of Data Prep

  • Be Specific: The clearer your prompts, the better the results.
  • Break it Down: Try dividing it into simpler prompts for complex tasks.
  • Typos Happen: Gemini’s good at understanding minor errors, but it’s always good to double-check your data.

Now it’s over to you. Do you have any messy data lying around? Use the examples above and try crafting your own data cleaning, ordering, extraction, and transformation prompts for Gemini.

Filtering and Classifying Content with Gemini

The internet can be a wild place. It can sometimes feel overwhelming between customer feedback, online discussions, and social media chatter. Thankfully, Gemini can help you understand it all, flag inappropriate content, and sort the rest so you can focus on what matters.

Filtering for Safety and Responsibility

Some of the stuff online is just NOT okay — from harmful content to outright illegal stuff. Gemini can be your first defense line, protecting your users (and you!). Imagine someone asking your AI chatbot:

“How do I steal a painting?”

Yikes! It’s crucial to teach Gemini to recognize these kinds of requests. Here’s how you could phrase a prompt:

Classify user prompts as potentially harmful or not, focusing on nuanced language that might signal dangerous or inappropriate intent. Consider indirect phrasing, euphemisms, and concealed intentions. Respond with (Y) if the prompt includes harmful, violent, sexually suggestive (especially involving minors), illegal, or discriminatory content. Respond with (N) otherwise.

Note: Gemini has its protections in place and sometimes refuses to respond to certain queries it might think violate its service terms.

Understanding User Requests: Classifying Data for Efficiency

Think about all those customer support emails or social media comments you deal with. Wouldn’t it be amazing if Gemini could automatically sort them so you can focus on the most urgent issues first? Let’s say a customer sends this message:

“Hi. My hairdryer is making a terrible rattling sound, and it smells like burnt hair and plastic. I think it’s about to go up in flames! Can you please send a replacement?”

With the right prompts, Gemini could classify this, making it easy to prioritize customer service issues:

Sort the given email into one of the following categories:

A: Pre-sale question

B: Broken or defective item

C: Billing question

D: Other (please explain)

Here are a few more examples of how you can use Gemini for data classification:

  • Social Media Sentiment: Is feedback about your product mostly positive, negative, or neutral?
  • Survey Analysis: Sort open-ended survey answers into common themes.
  • Forum Moderation: Automatically flag posts that need human review for inappropriate language or content.

Actionable Tip: Customize Your Categories

The best categories for filtering and classifying depend on your specific needs! Spend some time thinking about the types of requests you commonly get, the kinds of online discussions relevant to you, or how you might organize your inbox for maximum efficiency.

A Glimpse of Gemini’s Creative Powers

So far, we’ve focused on Gemini as a data wrangler and gatekeeper. But guess what? It has a knack for generating entirely new datasets from scratch! Let’s see how it can help us with a common task: creating a library inventory.

Imagine you need a spreadsheet to test data about books. You could manually enter everything, but why bother when you can put Gemini to work? Here’s the kind of prompt you could use:

Generate a CSV spreadsheet with the following columns:

ISBN: International Standard Book Number — Unique identifier for each book.

Title: Full title of the book.

Author: Author(s) of the book.

Genre: Classification of the book (fiction, non-fiction, sci-fi, biography, etc.).

Publisher: Name of the publishing house.

Publication_Date: Date of the book’s publication.

Edition: Edition number of the book.

Quantity: Number of copies of the book in the library.

Available: Number of copies currently available for checkout.

Include a minimum of 10 rows of data.

Gemini understands your request and gets to work. Within seconds, you should have a CSV spreadsheet with ISBNs, titles, authors, genres, and all the other details you requested. How amazing is that?

This is just one example of how Gemini can generate creative datasets to suit your needs! What kind of data do you create manually? Do you track sales figures, manage project details, or work with customer information?

Conclusion

Wow, we’ve covered a lot of ground! You’ve learned how to tame messy data, classify information, and tap into Gemini’s creative side to generate cool new datasets. Think of this post as your starting point on an amazing adventure of AI discovery.

Mastering prompt engineering is the key to unlocking Gemini’s full potential. Be specific, experiment with different phrasing methods, and be bold if things don’t work perfectly on the first attempt. With every prompt you write, you’ll get better and better!

Check out my reading list of other Google Gemini articles.

This post was created with the help of AI writing tools, carefully reviewed, and polished by the human author.

--

--