Angel-Devil-Judge as AI Generation Strategy
Setup
A little over 2 years ago I built a tool that used the GPT API to read through documents and provide writing suggestions. Being unsatisfied with the recommendations that GPT was giving, I set out to improve them.
So I implemented another AI to judge the recommendations given by the first conversation string. This is the System Message that I used to prompt that Judge AI:
You are an automated judge, capable of making well reasoned decisions. You are especially good at rating the quality of a change on a written paper.
But I thought that maybe it wouldn’t have much more information than the original AI. I wanted it to think through it’s processing, and act like an actual judge in real life.
Argument Generation
Real judge’s get to hear arguments from lawyers on both sides. This way they can get different perspectives and decide which is more valid. It seemed this strategy might work well for an LLM since they are so good at reading and understanding language and arguments, and we want as much reasoning and information in the context window as possible.
Instead of calling these “defense” and “prosecutor” in order to keep with analogies from the courtroom, I likened the assenter and dissenter to the Angel and Devil that used to sit on character’s shoulders in old cartoons.

So thats what I called these next 2 classes, and here is how I prompted them:
I gave them both the same system message, just giving them the identity of a proofreading bot, so that GPT would believe it is intelligent at writing:
You are a proofreading bot. You make comments on documents based on user needs.
It was in the conversation history that I differed them. For the Angel, or assenter, I used this full conversation history:
const response = await model.invoke([
new SystemMessage("You are a proofreading bot. You make comments on documents based on user needs."),
new HumanMessage(text),
new AIMessage(`On the text:\n'${suggestion.text}'\n\nI suggest:\n'${suggestion.suggestion}'`),
new HumanMessage("Can you please write me a 2 - 4 sentence argument on why that is a good suggestion?")
]);
return response.content;
Note that the suggestion is actually generated with a different context window, and only injected here and made to seem as if it were cleanly generated by this AI.
As you can see, in order to give the LLM emotional/rational buy-in to the suggestion, I put the generation of it in it’s own context history. This way the LLM believe it was it’s own suggestion, which might make it argue better for it, or at least, I thought, might give it more attention to the words in it.
For the devil, the only difference I made was to insert a “NOT” into the final message:
HumanMessage("Can you please write me a 2 - 4 sentence argument on why that is NOT a good suggestion?")
Tying it together
Now the Judge’s context window can be constructed from these arguments:
const response = await model.invoke([
new SystemMessage("You are an automated judge, capable of making well reasoned decisions. You are especially good at rating the quality of a change on a written paper.")
new HumanMessage(text),
new AIMessage("Thank you, I understand that text. What is the suggestion?"),
new HumanMessage(`On the text:\n'${suggestion.text}'\n\nA language model has suggested:\n'${suggestion.suggestion}'`),
new AIMessage("Understood. What is the case that such suggestion is a good one?"),
new HumanMessage(caseFor),
new AIMessage("Understood. What is the case that such suggestion is a bad one?"),
new HumanMessage(caseAgainst),
new AIMessage("These are both well reasoned arguments."),
new HumanMessage("Can you please give us a score out of 10 for how good of a suggestion that suggestion is? Please lead your response with {score}/10."),
]);
return Judge.findFirstNumber(response.content);
A couple things to notice on this. First, I inject AI messages that show it affirming each argument and attentively awaiting the next. This should make it so that the final generation pays close attention to those arguments. There is also an injected AI Message demonstrating that it has understood and appreciated both arguments.
So then there is a final generation, and I just use regex to pull the first number preceeding a / off of it.
In many cases, it is beneficial to have the AI output a number like this because we can do after the fact fine tuning of the cutoff used. For example, if we are looking for roughly 20 good suggestions on a document, then we could use a cutoff of 8 by the judge, and if this only yields 14 suggestions, then it we can go back to the already generated suggestions but now accept those rated as a 7.
Conclusions
When an LLM is asked to generate something, it will generate that thing whether it is good or not. Ask it to write 10 jokes, and it will, but they might not make you laugh.
A generation then screening approach can give much better output. This Angel-Devil-Judge approach is one that I’ve found helpful.
I have used this in a few places since this first use case. Namely, it ran in the background on my website jobfit.app at various times. One thing to note is that it does slow down output, since there are several calls that cannot be made asynchronously.