Use Few-Shot Prompting for Consistent Text Formats in ChatGPT
Job to be done: Generate consistent text formats using AI examples.
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Small business
Draft consistent WhatsApp replies for common customer questions (e.g., 'Is this available?', 'What's the price?') by providing examples of your usual responses.
- Entrepreneur
As a solo founder, generate consistent commit messages (e.g., `feat:`, `fix:`) for your product's codebase, ensuring clear version control history.
- Student
Format your research paper's bibliography entries into a consistent APA 7th edition style by providing examples of correctly formatted citations.
What you’ll get
You will get AI-generated text that matches a specific style or format you provide, such as consistent commit messages for your code projects or transformed data. This approach works by showing the AI a few examples, allowing it to learn the pattern and apply it to new inputs, saving you time on repetitive formatting tasks.
Tools you need
- ChatGPT (freemium): An AI chatbot for general questions and text generation.
- Cursor (freemium): An AI-powered code editor with a built-in chat assistant.
Steps
-
Open your AI tool: Go to ChatGPT (chatgpt.com) or open Cursor’s chat interface. You should see a text input field ready for your prompt.
-
Provide examples: Paste your existing examples that show the style or format you want the AI to follow. The author’s example uses commit messages:
Here are my commit messages so far: feat: add user authentication with JWT fix: resolve null pointer in payment service refactor: extract validation logic into middlewareYou should see your examples appear in the chat history.
-
Ask for a new output: After your examples, tell the AI what new item you want it to format, following the style of your examples.
Now write a commit message for: I added rate limiting to the API endpoints. Output:You should see the AI generate a new commit message that matches the style of your examples, like
feat: add rate limiting to API endpoints. -
(Optional) Transform data formats: You can also use this technique to convert data from one format to another. Provide examples of the “old format -> new format” pairs.
Convert this old API response format to a new one: Old: {"id": 1, "name": "Product A", "price": 10.00} New: {"productId": "1", "productName": "Product A", "unitPrice": "10.00"} Old: {"id": 2, "name": "Product B", "price": 25.50} New: {"productId": "2", "productName": "Product B", "unitPrice": "25.50"} Old: {"id": 3, "name": "Product C", "price": 5.00} New:You should see the AI complete the new format for “Product C” based on your examples.
Original source
This workflow is inspired by a blog post titled ‘10 Prompting Techniques My Deep Learning Exam Taught Me (That I Actually Use Now)’ by dj29, shared on the DEV Community platform. The author explains how academic AI prompting theories can be applied to practical developer tasks.
Notes & variations
- Free-tier alternatives: The free tiers of ChatGPT and Cursor are generally sufficient for this type of task. Other freemium AI chatbots like Google Gemini (gemini.google.com) or Claude (claude.ai) can also be used.
- Common mistake: Not providing enough clear examples. If the AI doesn’t pick up the pattern, try adding one or two more examples that clearly show the desired style or transformation.
- Tip for better results: Make your examples as consistent and distinct as possible. Highlight the specific elements you want the AI to learn (e.g., the
feat:prefix, the casing, the level of detail).