Skip to content

Prompt Engineering for Developers

Principles

Principle 1: Write clear and specific instructions

  • Use delimiters: "", <>
  • Ask for structured output format.
  • In the prompt, include checks to make sure that the response given by the model respect some set of conditions

Principle 2: Give the model time to think

  • Specify the steps to complete a task.
  • Ask the model to work out its solution before rushing up to the conclusion

Examples of prompts

Is the writer of the following review expressing anger? The review is delimited with triple backticks. Give your answer as either yes or no.

Does the writer of this review is expressing a positive or negative sentiment? Give your answer as positive or negative followed by words in the review that justify that analysis.

Improving answer determinism

A desirable property of an application with LLMs is to create a prompt which could be somehow deterministic. By that, I mean that the prompt is tailored in a way such that it can verify itself and then return a yes or no answer (remember of decision problems in computer science). I am anticipating that besides yes and no, we would also have an unknown answer. If we are able to create small prompt modules that boils down to these three answers, I believe we can be more confident about the accuracy of the answer. Therefore, a chaining of prompt modules will not terribly suffer from lost of accuracy (i.e. 0.9^10=0.34 but 0.9999^10=0.999).

Topics covered:

  • Summarizing. "Write an one-sentence long summary of the story between quote marks."
  • Inferring. "Determine the topics covered by the text in between quotes. For each topic, answer with 0 if the topic is not covered in the story; and with 1 it it is covered.
  • Transforming: Translation between natural languages; formal and informal; formal languages (programming languages).
    • proofreading(nice example in conjunction with python library redlines. This shows the diffs in the text.);
    • ask for a specific format: json, markdown, APA style (set of guidelines developed by APA for different types of documents.)
  • Expanding: This is about give some pieces of information and ask the LLM so make more from it.
    • Give a topic and ask it to write a message or an e-mail about it.
    • Give a review from a client, identify the sentiment of the text and then respond to the client with an appropriate message according to the sentiment: negative, neutral, positive.
    • You can use the parameter temperature to regulate the randomness (or creativity) of the model. A zero temperature is the most deterministic you can get.

Chatbot

In the OpenAI API of ChatGPT, you can pass a collection of messages (context) in order to get a response. Each message can have a "role" among those: {"user","assistant", "system}. The first two are self-explanatory. The third one is like whispering in the assistant ear, to give it particular instructions.

Conclusion

  • Clear write and specific instructions.
  • Give the model appropriate time to think (possible breaking down tasks in a step-by-step fashion)
  • Capabilities: Summarizing, Inferring, Transforming, Expanding.