FDE Times dataFDE jobs open 928▲21 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 85Companies hiring 200Remote-friendly 24%Median US pay $200kTop hirer Databricks 107
中文VI

The newspaper of the Forward Deployed Engineer

Guides

How structuring calls took GPT-4 from 4% to 74% on one puzzle

For client decisions that cannot go wrong, four layers of self-checking show which are worth paying for and which only inflate the API bill.

ShareLinkedInFacebookX

In brief

  • Self-consistency sends the same prompt several times and takes the majority answer. The original paper reported a 17.9% gain on GSM8K.
  • Step-back makes the model state a general principle before it reasons. Tree of thoughts has the model generate and score ideas, then searches them with BFS or DFS.
  • Each layer multiplies the number of model calls. Keep them for costly decisions, and do not tell reasoning models to think step by step.
Dot plot of model calls per question: self-consistency 5, prompt ensembling 9, tree of thoughts 30 (highlighted in orange).
With the set-up in the article, tree of thoughts needs 30 calls per question, more than three times prompt ensembling. Source: calculated from the sample code in the article.

On the GSM8K maths benchmark, simply asking a model several times and taking the most common answer raised accuracy by 17.9% over chain-of-thought with greedy decoding. On the Game of 24, GPT-4 with chain-of-thought solved only 4% of problems. With tree of thoughts it solved 74%.

Those numbers come from benchmarks, not from client systems. Still, they show something every FDE eventually runs into: with the same model, the way you structure your calls can matter as much as the prompt.

On a client site, some decisions cannot be allowed to go wrong: approving or rejecting an application, picking a supplier, deciding whether to escalate an incident. This guide shows you how to build a small four-layer framework. It also shows which layers are worth the money and which only push up the API bill.

What you will build, and what you need

Take a hypothetical case. The client is an insurer that wants a model to read a claim file and the policy terms, then decide CHI_TRẢ (pay) or TỪ_CHỐI (reject). One model call gives you an answer, but it does not tell you how sure the model is. The goal is to replace that single guess with a vote that comes with numbers.

You need Python 3 and the SDK for whichever model provider the client uses. The code below is simplified. call_llm is only a placeholder for the real SDK, and parameter names and error handling will vary by provider. The prompts and labels are in Vietnamese. The output marker CONCLUSION: means “CONCLUSION:”.

from collections import Counter

def call_llm(prompt: str, temperature: float = 0.7) -> str:
    # Assumption: replace with your real SDK call
    raise NotImplementedError

def extract_answer(text: str) -> str:
    # Convention: the model ends with the line "CONCLUSION: <label>"
    for line in reversed(text.splitlines()):
        if line.startswith("CONCLUSION:"):
            return line.split(":", 1)[1].strip().upper()
    return "UNCLEAR"

Take the conclusion line seriously. If you cannot enforce the output format, you cannot count votes, and every later step breaks.

Step 1: ask the same question five times and count the votes

Chain-of-thought with greedy decoding follows a single reasoning path. Self-consistency instead samples several reasoning paths and picks the answer they agree on most. In practice, you send the same prompt several times with temperature above 0 and take the majority answer.

def self_consistency(prompt: str, n: int = 5):
    answers = [extract_answer(call_llm(prompt, temperature=0.7))
               for _ in range(n)]
    votes = Counter(answers)
    label, count = votes.most_common(1)[0]
    return label, count / n, votes

Check: run it on one claim. If you get 3 votes for TỪ_CHỐI and 2 for CHI_TRẢ, the final label is TỪ_CHỐI with an agreement rate of 0.6.

A claim with 5/5 votes may well be a genuinely confident answer, especially for easy cases. Only when every claim in the test set scores 5/5 should you look at the temperature again, because you may not really be sampling.

On a client site, return the agreement rate along with the label. A claim with 5/5 votes and a claim with only 3/5 should not go through the same process.

Step 2: change the angle with prompt ensembling

Self-consistency samples from a single prompt. If that prompt is biased, all five votes can lean the same way. Prompt ensembling deals with this by running several prompts on the same problem and combining their answers into one result.

PROMPTS = [
    "You are a claims adjuster. Case file: {case}\n"
    "End with 'CONCLUSION: PAY' or 'CONCLUSION: DENY'.",
    "List every exclusion clause relevant to the case file: {case}\n"
    "Then end with the CONCLUSION line as above.",
    "Act as a reviewer and look for reasons this case was handled wrongly: {case}\n"
    "Then end with the CONCLUSION line as above.",
]

def ensemble(case: str, n_each: int = 3):
    all_votes = Counter()
    for tpl in PROMPTS:
        _, _, votes = self_consistency(tpl.format(case=case), n=n_each)
        all_votes.update(votes)
    label, count = all_votes.most_common(1)[0]
    return label, count / sum(all_votes.values()), all_votes

The three prompts take the view of a claims handler, list the relevant exclusion clauses, and argue as a critic looking for reasons the claim was handled wrongly. Three prompts with three samples each makes 9 calls. If the result is 6 votes for TỪ_CHỐI and 3 for CHI_TRẢ, the agreement rate is about 0.67. Set a threshold, say 0.7, and send every claim below it to a human reviewer. Calibrate the actual threshold on the client’s data instead of picking it by feel.

Common mistake: writing three prompts that differ by only a few words. That gives you self-consistency at three times the cost. The prompts need different perspectives, such as the handler, the policy terms and the critic.

Step 3: step back before deciding

Step-back prompting has two steps. First the model is asked to focus on a more general concept or principle related to the question. Then it uses that principle to reason.

The original paper reported that the technique improved PaLM-2L by 7% on MMLU Physics and 11% on MMLU Chemistry. Learn Prompting’s summary puts the gain over chain-of-thought at between 7% and 27%, depending on the task.

def step_back(question: str, case: str) -> str:
    principle = call_llm(
        "Don't answer yet. What general principle decides "
        f"this type of question?\nQuestion: {question}", temperature=0)
    return call_llm(
        f"Principle: {principle}\nCase file: {case}\n"
        "Apply the principle to the case file. End with the CONCLUSION line.",
        temperature=0)

Check: print principle and give it to the client’s domain expert to read. This side benefit is valuable on a client site: a wrong principle gets caught at step one, before it drags the conclusion down with it.

Step 4: tree of thoughts for problems with many branches

Some decisions have more than two labels, such as a dispatch plan made of several steps that depend on each other. Tree of thoughts handles these by having the model generate ideas and score them itself, then combining that with a search algorithm such as BFS or DFS. The version below is a cut-down BFS and is heavily simplified compared with the original paper.

def score(path: str) -> float:
    s = call_llm("Rate from 1-10 how promising the following line of reasoning is. "
                 f"Return only a number.\n{path}", temperature=0)
    try:
        return float(s.strip())
    except ValueError:
        return 0.0

def tot_bfs(problem: str, depth=3, breadth=3, keep=2) -> str:
    frontier = [""]
    for _ in range(depth):
        candidates = [
            path + "\n" + call_llm(
                f"Problem: {problem}\nSteps so far:{path}\n"
                "Propose ONE next step.")
            for path in frontier for _ in range(breadth)]
        ranked = sorted(candidates, key=score, reverse=True)
        frontier = ranked[:keep]
    return frontier[0]

Count the calls before you run it. The first level has 1 branch times 3: 3 generation calls and 3 scoring calls. The second and third levels each have 2 branches times 3: 6 generation calls and 6 scoring calls. That makes 30 calls for one question, 30 times the cost of a single prompt.

When not to use this framework

The Prompt Engineering Guide notes that reasoning models are much more expensive and slower than ordinary chat LLMs. Use them only for the parts that really need reasoning.

Running a 9-call ensemble on a reasoning model means 9 times a per-call price that is already much higher. Try it first on a cheaper model, measure whether the improvement is real, and upgrade only after that.

The same guide also advises against putting chain-of-thought instructions such as “think step by step” into prompts for reasoning models. A common mistake is to move the step 2 prompts to a reasoning model unchanged. Keep the context and the conclusion format, drop the step-by-step instructions, and measure again.

How this skill shows up on a client site

Clients rarely ask about self-consistency. They ask: “What happens when the model is wrong?” The best answer is a concrete process. High-agreement claims go straight through, low-agreement claims go to a human reviewer, and you have a table showing the share of each group.

On your CV, do not write “proficient in prompt engineering”. Describe the work: you used a three-prompt ensemble with an agreement threshold to send a share of hard cases to human review, measured it on a labelled dataset, and reported your own numbers, not borrowed benchmark figures.

These four techniques do not make the model smarter. They give it more chances to disagree with itself, and those disagreements show you where a person needs to check the result.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
9 sources
Read next on the roadmap · Stage 3: Applied AIBuild a system prompt that survives the second departmentSplit it into four layers (role, policies, customer context and department configuration), so each new team costs one config block rather than another copy.