Arguing with yourself on purpose: a counterargument engine

Opinion engines are a popular kind of small AI project: type a topic and get a hot take, an expert-style analysis or a devil's advocate response that argues against the obvious view. Built well, such a tool is genuinely useful. Writers test their arguments before publishing, product teams find weaknesses in a plan before a meeting, students practise debate and anyone can check whether they are only hearing one side.
Built carelessly, the same tool becomes a machine for confident nonsense. This guide shows how to build the useful version. You will design prompts for several argument modes, request structured JSON so your interface can display claims and evidence separately, add a critique step that flags weak points, and run it all against the keyless free-ai endpoint on this site or any OpenAI-compatible provider such as Groq.
Frequently asked questions
What is a devil's advocate in this context?
It is a deliberate argument against a position, made to test that position rather than because the arguer believes it. The goal is to find weaknesses, overlooked costs and alternative explanations before someone else does.
What does steelmanning mean?
Steelmanning means presenting the strongest, most charitable version of a view you disagree with. It is the opposite of a strawman, which attacks a weak caricature. A good opinion engine steelmans by default.
How do argument modes differ from each other?
A counterargument attacks a stated claim. A steelman builds the best case for an opposing view. A pre-mortem imagines that a plan failed and explains why. An expert analysis weighs both sides. Each mode needs its own instructions.
Why use JSON output for arguments?
Structured output lets the interface show each point with its reasoning and the kind of evidence that would support it, sort by strength and let users expand details. It also makes it easy to validate that every point has the required fields.
Can the model invent evidence for its arguments?
Yes. Language models readily invent studies, statistics and quotes to support a position. Ask for the type of evidence that would matter instead of specific citations, and tell users to verify anything presented as fact.
Does a model with fewer refusals argue better?
It will engage with more controversial positions instead of declining, which helps for debate practice. It does not reason better because of that, and it will also argue weak positions convincingly, so the critique step matters even more.
Which is better for this, a small or a large model?
Larger models produce more original, less generic counterarguments and notice subtler flaws. A mid-sized model is fine for brainstorming and quick checks. For publication-quality analysis, a strong commercial model usually wins.
How is this different from a normal chatbot conversation?
A normal chat answers whatever you ask in the assistant's default voice, which tends to agree and soften. An argument engine fixes the role, the structure and the output format, so every run produces comparable objections you can sort, critique and track over time.
Step by step
- Define the argument modes — Decide which modes the tool offers, such as counterargument, steelman and pre-mortem, and write a short instruction for each.
- Specify a JSON schema — Ask for a list of points, each with a claim, reasoning, the evidence that would support it and a strength rating.
- Call the API and validate — Send the user's claim with the chosen mode, parse the JSON and retry once if fields are missing.
- Add a critique pass — Send the generated points back with instructions to flag unsupported or fallacious reasoning.
- Display with honest labels — Show points, critiques and a note that the output is generated and must be checked before use.
Why build an argument engine at all
People are bad at arguing against their own views. We notice evidence that supports what we already think and skim past the rest. A tool that reliably produces the strongest objections to a plan or a draft article is a cheap way to counter that bias. It does not decide who is right; it makes sure the other side has been heard.
The same mechanics serve many products: a writing assistant that challenges a thesis, a decision tool for teams, a debate trainer, a newsletter feature that presents two views on a topic. All need the same core: clear modes, structured output and a guard against invented facts.
What the tool should not do
It should not present generated opinions as facts, invent sources or produce one-sided content designed to inflame. If your product shows hot takes, label them as provocations and pair them with the counterview.
Designing argument modes
Each mode is a short instruction added to a shared system prompt. Keeping them separate makes it easy to tune one without affecting the others and to add new modes later.
Resist the urge to add many modes at once. Three well-tuned modes beat ten vague ones, and each new mode is another prompt to test whenever you change models. Start with counterargument and steelman, watch how people use them, and add a pre-mortem or balanced analysis once you see demand.
Counterargument
Take the user's claim at face value and produce the strongest objections: hidden assumptions, overlooked costs, alternative explanations and cases where the claim fails.
Steelman
Build the most persuasive version of the opposing position, as a thoughtful advocate would present it, without caricature or sarcasm.
Pre-mortem
Assume a plan was carried out and failed a year later. List the most plausible reasons, ordered by likelihood, with early warning signs for each.
Balanced analysis
Lay out the main arguments on both sides, note where they disagree on facts versus values, and say what information would settle the factual parts.

A JSON schema for arguments
Free-form paragraphs are hard to display well and impossible to validate. Ask for a fixed structure instead. Each point gets a short claim, a sentence or two of reasoning, the kind of evidence that would support it and a self-rated strength. The evidence field asks for a type, such as "cost data from similar projects", rather than a citation, which sharply reduces invented references.
Why self-rated strength is still useful
The model's own rating is not reliable as a measurement, but it helps order points for display, and users can override it. Treat it as a sorting hint, not a verdict.
- claim: one sentence stating the point
- reasoning: why the point matters, two sentences at most
- evidence_needed: the kind of data or source that would support it
- strength: low, medium or high, as judged by the model
- assumption: the assumption in the original claim that this point targets
The generator in Python
The function below implements the modes and schema, calls the keyless endpoint and validates the result. If parsing fails or fields are missing, it retries once with a reminder. Swap the base URL, key and model to run the same code against another provider.
Why json.JSONDecodeError is caught as ValueError
The JSON decode error is a subclass of ValueError, so one except clause handles both malformed JSON and the missing-points case. Keeping error handling simple makes the retry logic easier to follow.
import json
from openai import OpenAI
client = OpenAI(base_url="https://api.apifreegroqkey.com/v1", api_key="free")
MODES = {
"counter": "Give the strongest objections to the claim: hidden assumptions, costs, alternative explanations.",
"steelman": "Build the most persuasive version of the opposing view, charitably, without sarcasm.",
"premortem": "Assume the plan was carried out and failed a year later. Explain the most plausible reasons.",
}
SCHEMA = ("Return JSON only: {\"points\": [{\"claim\": str, \"reasoning\": str, "
"\"evidence_needed\": str, \"strength\": \"low|medium|high\", \"assumption\": str}]}. "
"3 to 5 points. Do not cite specific studies or statistics; describe the evidence type instead.")
REQUIRED = {"claim", "reasoning", "evidence_needed", "strength", "assumption"}
def parse(text):
data = json.loads(text[text.find("{"):text.rfind("}") + 1])
points = [p for p in data.get("points", []) if REQUIRED <= set(p)]
if not points:
raise ValueError("no valid points")
return points
def argue(claim, mode="counter"):
messages = [
{"role": "system", "content": MODES[mode] + " " + SCHEMA},
{"role": "user", "content": claim},
]
for _ in range(2):
r = client.chat.completions.create(model="free-ai", messages=messages,
temperature=0.7, max_tokens=1200)
text = r.choices[0].message.content
try:
return parse(text)
except ValueError:
messages += [{"role": "assistant", "content": text},
{"role": "user", "content": "Invalid. Reply with the JSON object only."}]
raise RuntimeError("model did not return valid JSON")
for p in argue("Our team should rewrite the backend in a new language this quarter.", "premortem"):
print(f"[{p['strength']}] {p['claim']}")
Adding a critique pass
Generated arguments vary in quality. Some are sharp; others are vague, circular or rely on a fallacy. A second call that reviews the points catches many of these. Send the original claim and the generated points, and ask the model to flag any point that is unsupported, attacks a position nobody holds, relies on a slippery slope or appeal to fear, or merely restates another point.
Display the flags next to the points rather than silently deleting them. Users learn more from seeing why an argument is weak than from a cleaned list, and they can judge whether the critique itself is fair.
A critique pass also gives you a cheap quality metric. Track the share of points flagged in each mode over time. If a model update or prompt change suddenly doubles the flag rate, you know something regressed before users start complaining about weak arguments.
Use a different temperature
Run the critique at a low temperature, such as 0.2, so it is consistent and conservative. Generation benefits from some randomness; review benefits from predictability.
Limits and quotas for an interactive tool
Each request with generation plus critique is two API calls. The keyless endpoint allows one request per second per IP, two in parallel, and 10,000 requests or 10 million tokens per day, resetting at 00:00 UTC. That suits a personal tool or a demo. A public website with many visitors would funnel all traffic through your server's IP and hit those limits fast, so a paid provider is the right choice at that scale.
Groq is a common choice for tools like this because its fast responses make interactive argument generation feel snappy; check its current model list, free-tier limits and pricing before building on it. This site is not affiliated with Groq, and the keyless endpoint does not serve Groq's models. Our comparison of subscription and per-token pricing can help estimate costs.
Cache popular topics
If many users ask about the same well-known debates, cache results for a while. It saves calls and gives consistent answers, though you should refresh periodically and still show the generated-content label.

Responsible use and sensitive topics
free-ai is an independent open-weight model of about 35B parameters, tuned to refuse far less than commercial assistants. For a debate tool, that means it will argue unpopular or controversial positions that other assistants might decline, which is useful for practice and for understanding opposing views. It keeps two hard limits: no sexual content involving minors and no operational instructions for mass-casualty weapons.
Fewer refusals shift responsibility to you as the builder. Decide which topics your product supports, add your own content rules, and avoid modes that produce harassment of real people or deliberate misinformation. Arguing that a policy has hidden costs is debate; generating fake quotes from a named politician is not. Our article on the limits of AI forecasts covers a related risk: confident generated claims about real events.
Keep real people out of generated attacks
Add a rule that arguments address positions and policies, not the character of named individuals. It keeps the tool useful and avoids defamation problems.
Ideas for extending the tool
Once the core works, small additions make it more valuable. A rebuttal mode lets users respond to a point and get a counter-response, turning the tool into a sparring partner. A comparison view shows counterarguments from two different models side by side, which reveals how much of the output is the model's style rather than the topic. A document mode takes a draft article and returns objections paragraph by paragraph.
For developers who want to test which model argues best for their audience, our guide to benchmarking providers on your own prompts applies directly: use a fixed set of claims, blind the outputs and rate them.
Let users rate the points
A simple thumbs up or down on each point builds a dataset of what your users find convincing. Over time it shows which modes and prompts produce useful objections and which produce filler.

Send a request to the keyless free-ai endpoint from the home page and see how it fits your project, no sign-up needed.
Read also
- How to Clean Up Speech-to-Text Dictation With an LLM API
- How to Build a Document Q&A Service With FastAPI and an LLM API
- What Is Graph RAG, and When Does It Beat Plain Vector Search?
- LangChain vs the Plain OpenAI SDK: Which Should Your LLM App Use?
- Can an LLM Predict Markets or Conflicts? The Limits of AI Forecasts