blog-img

Improve Prompts


Prompts are the foundational building blocks for building an artificial intelligence system. Improving prompts in FastBuilder.AI for better code generation involves a few key steps. Since FastBuilder.AI leverages prompts to drive its code generation capabilities based on a product story and knowledge graph, the quality of the generated code is directly influenced by how clear, specific, and relevant the prompts are. Here’s how to improve prompts:

1. Increase Prompt Specificity

  • Define precise instructions: Ensure your prompts are highly specific about what needs to be done. Vague prompts may result in generic or incorrect code.
  • Bad prompt: “Create a function for user login.”
  • Improved prompt: “Create a function in Python that authenticates a user using email and password, and returns a session token upon success or an error message if the login fails.”
  • Clarify input/output expectations: Specify the data structure, input types, and expected outputs. This helps avoid ambiguity in code generation.
  • Example: “Create a Python function that accepts a list of integers as input and returns a list of integers that are prime numbers.”

2. Align with Knowledge Graph

  • Leverage domain-specific context: If FastBuilder.AI uses a knowledge graph to map relationships within the product story, ensure the prompt aligns with the key entities, relationships, and dependencies defined in the graph. Use relevant terminology from the knowledge graph to add context.
  • Example: If the knowledge graph involves a “user authentication” story, mention relevant entities like “session management,” “login attempts,” or “multi-factor authentication (MFA)” in the prompt.

3. Use Constraints or Conditions

  • Add constraints for better precision: Specify conditions under which the generated code should operate. This might include language-specific constraints, performance considerations, or security standards.
  • Example: “Generate a JavaScript function to hash a password using SHA-256, but ensure it can handle password inputs of any length and does not use any deprecated libraries.”

4. Break Down Complex Tasks

  • Split large tasks into smaller prompts: Instead of creating one large prompt for a complex feature, break it down into multiple smaller prompts that handle individual aspects of the task. This improves clarity and enables more accurate code generation.
  • Example: If you need a full user authentication system, create separate prompts for:
  1. Database schema for users
  2. API endpoint for login
  3. Function to verify credentials
  4. Function for password recovery

5. Iterative Improvement

  • Refine based on feedback: If the generated code is flawed, analyze the issues and identify why the prompt might have been unclear. For example, if the generated code uses an outdated library, include more specific instructions in the prompt about library versions or standards.
  • Example: If a prompt generated inefficient code, you can modify it to say, “Generate a Python function to sort a list of integers using a time-efficient algorithm such as quicksort.”

6. Test Edge Cases in Prompts

  • Anticipate exceptions or uncommon scenarios: You can include prompts that specify how to handle edge cases, errors, or invalid inputs, making the generated code more robust.
  • Example: “Create a function to divide two numbers, ensuring it handles the case where the denominator is zero by returning an appropriate error message.”

7. Review Generated Code Regularly

  • After generating code, review it for common flaws like inefficiencies, security vulnerabilities, or outdated practices. Based on these reviews, you can refine prompts to address the specific weaknesses encountered.

By iterating on prompts, ensuring alignment with the knowledge graph, and adding specificity and constraints, you can significantly improve the quality of code generated by FastBuilder.AI.



Next : How to improve AI for better code generation?


Updated: Oct 11, 2024