The Art of Prompt Engineering (Or: How I Learned to Stop Worrying and Trust the AI)
First attempt at prompting Gemini:
Result: "Have you considered going somewhere? Perhaps doing things when you get there? Maybe eating food?"
Right. Maybe I need to be a bit more specific. Turns out "plan a nice trip" is to Gemini what "fetch" is to a golden retriever - technically understood, but interpreted rather loosely.
Take Two: The First Real Attempt
My first serious attempt at structuring the prompts was... well, let's say Wooster had some creative interpretations:
Result: "Day 1 you could maybe explore downtown? Stay as long as you're having fun! Costs depend on how many treats you buy along the way. Some people spend a little, some spend a lot. Day 2 there's this AMAZING park the locals love..."
Not quite the structured response I was hoping for. Time to try JSON.
Adding More Structure (But Not Enough)
Here was my first JSON attempt:
This worked better, but the categorization was a mess. I got everything from "Fun stuff" to "Walking around looking at things" as categories. It was like asking Wooster to sort his toys - everything ended up in the "things I can put in my mouth" category.
Take this response for example:
Time to get serious about types.
The Final Evolution
After much trial and error (and Wooster suggesting "belly rubs" as a valid activity category), I landed on this much more structured approach:
And later, after realizing I needed geolocation for mapping of activities:
Finally, I was getting responses that looked like actual travel plans rather than Wooster's diary entries:
Still with a hint of Wooster's personality, but now in a format that wouldn't make TypeScript cry.
Handling the Responses
Of course, getting the prompt right was only half the battle. Gemini's responses weren't always perfectly formatted JSON, so I needed some utility functions to clean things up:
Why did I need all this? Well, Gemini had some... interesting habits:
Sometimes wrapping responses in markdown code blocks
Occasionally including helpful comments (which broke the JSON)
Returning incomplete URLs
Adding mysterious control characters
And my personal favorite: sneaking in emoji (those non-printable characters had to go)
Using these utilities together:
What I Actually Learned
Start with strict types from the beginning
Be explicit about formats
The more specific the prompt constraints, the better
Always sanitize and validate AI responses
Geolocation data should have been there from the start
Rate limiting is important
Regex is your best friend when dealing with AI responses
Never trust an AI to format URLs correctly
Next up: the frontend implementation, or as I like to call it, "Making Wooster Look Presentable for Company" (and this time with proper TypeScript interfaces from day one).
Next up: wrestling with Express endpoints, where I discover that parsing AI
responses is like teaching Wooster that "sit" and "lay down" are different
commands.