Introduction

In this lesson, we're turning our attention to a specific technique for getting single-word output from LLMs. We'll use the example of designing an AI tutor that provides verdicts on code correctness. Our goal is to refine our prompts so that this AI tutor can succinctly report whether a piece of code is correct with a single word: "True" for correct and "False" for incorrect.

Getting a single-word output, in this case, is crucial for several reasons. Firstly, it allows for easy parsing and integration into larger systems, enabling seamless automation and decision-making processes. Secondly, it reduces the complexity of handling the output, as there's no need to interpret or filter through additional text. This simplicity is particularly beneficial in AI tutor development, where quick and clear feedback is essential for effective learning experiences.

The Challenge of Obtaining Binary Verdicts

When we task LLMs with evaluating code, the natural inclination of these models is to provide detailed feedback, explanations, or even corrected versions of the code. However, for an AI tutor scenario, we need it to distill its evaluation into a binary choice — correct or incorrect. Mastering this prompt design challenges us to direct the LLM's focus away from its propensity for elaboration towards a stark, binary output.

Consider a typical, less focused prompt:

Sample output:

The code correctly implements a function to print the Fibonacci sequence up to, but not including, a given number n. It's correct in its functionality.

Refining Prompts for Binary Code Verdicts

To ensure we receive a "True" or "False" response regarding the correctness of a code snippet, clarity and specificity are key in our prompts. We must explicitly request that the model's output be limited to one of these two options, eliminating the opportunity for additional commentary.

Here's how to adjust our prompt for this purpose:

Sample output:

True

You can see that we added two things, an explicit CONSTRAINTS: not to include an intro or outro, which is very common with LLMs, as well as a specification to give a one-word response.

If we wanted to make this prompt even better, we could include an example to demonstrate the expected output format, reinforcing the requirement for a single-word response.

Additional Applications for Binary LLM Responses

Binary responses from LLMs are useful in various scenarios:

  1. Sentiment Analysis: Classify reviews as "Positive" or "Negative" to quickly assess customer satisfaction.

  2. Spam Detection: Identify emails as "Spam" or "Not Spam" to maintain clean inboxes.

  3. Fraud Detection: Flag transactions as "Fraudulent" or "Legitimate" to secure financial activities.

These binary outputs simplify integration into automated systems, enabling swift decision-making.

Time to Practice

Now it's time to try building prompts like this on your own to solidify your understanding. Use the UI to chat with the LLM and refine your prompts to achieve the desired single-word output.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal