Vibe Coding - Effective Prompts



A prompt is an instruction to LLM or Generative AI in natural language. A prompt can be used to ask a question to the AI, or place a request to do some task.

Example of Prompts

Following are few examples of prompts

Prompt as a Question

How to create a submit button on a form?

Prompt as a Request

Create a blue button that opens a dialog box when clicked.

Prompt as a Task

Create a Product Page showing details of Shoes with option to add item to the cart. Product title, image, description and price should come from a json file.

Creating Effective Prompts

Set Context

For a prompt to work perfectly, we should create a broad context first and then give specific instructions to the AI. Consider the following case.

Write a function to compute prime numbers.
Input should be integer and function should return true or false if input is prime or not.
In case input is not integer, throw an error.

Break bigger complex tasks to simpler tasks.

This way we can manage a large task and maintain as development progresses. Consider the following case of creating a search word puzzle.

Create a function which can generate a grid of 10 by 10 letters.
Create a function to search words in grid of letter using a work list given in json file.
Write the function to use above functions to generate grid of 10 by 10 words with 10 random words to search.

Avoid Ambigous statements

Ambigous and vague terms are poor prompts as they can lead to multiple responses. It is always better to refer what we want AI to. For example instead of saying −

Fix the error.

We can say

Fix the email validation error in email input field.

Maintain Conversational History

Generative AI maintains a conversational history to maintain the context of the development. So it is always best to utilize this feature.

  • Create a fresh thread for new functionality or project.

  • Remove any irreleveant request or discared response to avoid confusion in next responses.

  • Conversation should be focused on one functionality at a time instead of mixing all functionalities in a single conversation.

Strategies to improve AI responses

If AI responses are not aligned then we can deploy following strategies to improve AI suggestions.

Refine the Search

  • Add specific requirements.

  • Examples of sample input and output can be added in the prompt.

  • Specify the programming language or framework the code is to be produced in.

Ask for modifications

Ask AI to modify previous response. For example −

  • Improve previous function with error handling.

  • Simplify the code generated.

  • Add type checks to the code.

Build in Incremental Order

Ask AI to start with basic version and then

  • Ask for enhancements.

  • Add features one by one instead of specifying all features in single prompt.

  • Test each feature added in iterative way and then proceed further to next feature.

Advertisements