Skip to content
TheChatArchiveThe Chat Archive
o3-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

What frameworks help with automatic prompt optimization? I'd like to be able to have an…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-lite-preview-06-17-thinking’s answer.
  1. User

    What frameworks help with automatic prompt optimization? I'd like to be able to have an LLM automatically make tweaks to my prompts and then another LLM judge if the response quality has improved.

  2. Assistant

    Below is a (non-exhaustive) map of the tools people actually use today when they want:

    • an LLM-A (“optimizer”) that proposes prompt variations
    • an LLM-B (“grader”) that decides which variation is better
    • a loop that keeps the winner and iterates

    I grouped the options by how much “batteries included” they give you.

    ────────────────────────────────────────────────────────

    1. End-to-end libraries that already automate BOTH tweak + judge ────────────────────────────────────────────────────────
    ProjectWhat it gives youHow it worksNice extras
    DSPy (Stanford)dspy.Optimizer object that rewrites prompts until eval score improvesUses an LLM as “teleprompter” to mutate instructions; evaluator can be accuracy metric, rubric-LLM, or human labelsWorks with OpenAI, Anthropic, Cohere, HuggingFace; also auto-creates few-shot examples
    Self-Refine (CMU, 2023)Very small Python lib + paper“Critic” LLM writes feedback and “Resolver” LLM rewrites the original answer/prompt; loops until no further gainMinimal, easy to plug into other stacks
    OPRO (Large Language Model as Optimizer, Anthropic paper)Simple algorithm + open-source demoOptimizer LLM generates natural-language prompts that attempt to maximize a numeric score returned by an evaluatorWorks well for short prompts; good baseline

    ──────────────────────────────────────── 2. Frameworks that give you the LOOP, plug in any LLM ────────────────────────────────────────

    ProjectPrimary rolePrompt tweak helper?Built-in evaluation?Notes
    LangChainChains/agentsHumanMessagePromptTemplate, load_prompt, FewShotPromptTemplate; plus PromptHub with versioninglangchain.evaluation (criteria, Q-A, ragas-style) can call GPT-4 as graderExample ↓
    OpenAI EvalsEvaluation harnessYou mutate the prompt however you like; loop is up to youYes – “LLM-as-judge” or exact answers; YAML specUsed by OpenAI for leaderboard
    TruLensObservability + feedbackNot opinionated on mutationYes – “feedback functions” (toxicity, factuality, etc.) can be GPTGives dashboards
    PromptLayer EvalsSimilar to TruLens but SaaS—YesFree tier, nice UI
    PromptTools (by zeke)CLI + VS Code extManual or scripted prompt gridsCompares outputs with diff view; can call LLM graderQuick for A/B testing
    RAGAS (RAG eval)Metrics (faithfulness, answer relev.)—YesIf you’re optimizing RAG system prompts

    ──────────────────────────────────────── 3. Agent / RL style systems you can bend to prompt engineering ────────────────────────────────────────

    • Auto-GPT, BabyAGI, CrewAI – give them an objective like
    "Improve this prompt’s BLEU score on the dev set" and they’ll iterate.
    • RL frameworks (trlX, HuggingFace TRL, Ax-RL) – treat the prompt text as the “policy parameters,” reward = grader score. Good for research, pricey in tokens.

    ──────────────────────────────────────── 4. SaaS products that hide the plumbing ────────────────────────────────────────

    PromptPerfect, PromptOps, Helicone “Autoprov”, Galileo, Portkey, Humanloop Playground, etc. They often expose a “prompt tuner” button that secretly runs something like OPRO behind the scenes and logs the winners.

    ──────────────────────────────────────── 5. Sketch of a DIY loop in ~40 lines (LangChain + OpenAI Evals) ────────────────────────────────────────

    from langchain.chat_models import ChatOpenAI
    from langchain.prompts import PromptTemplate
    from langchain.evaluation import load_evaluator
    from tqdm import trange
    
    optimizer_llm = ChatOpenAI(model="gpt-4o", temperature=0.9)
    worker_llm    = ChatOpenAI(model="gpt-4o", temperature=0.7)
    grader_llm    = ChatOpenAI(model="gpt-4o", temperature=0)
    
    # 1) seed prompt
    base_prompt = """
    You are a helpful, precise math tutor.
    Explain your reasoning step by step.
    """
    
    evaluator = load_evaluator("criteria",
                               llm=grader_llm,
                               criteria={"quality":"overall_quality"})
    
    def mutate(prompt):
        """Ask GPT to rewrite the prompt in one shot."""
        system = "You improve prompts. Return *only* the new prompt."
        ask = f"Original prompt:\n{prompt}\n\nRewrite it to get better answers."
        return optimizer_llm([("system",system),("user",ask)]).content.strip()
    
    def score(prompt, question="What is 13*17?"):
        q_template = PromptTemplate.from_template(prompt + "\n\nQuestion: {q}")
        answer = worker_llm(q_template.format_prompt(q=question)).content
        eval_json = evaluator.evaluate_strings(
                       prediction=answer,
                       input=question,
                       reference="221"    # gold answer
                    )
        return eval_json["score"], prompt
    
    BEST = (-1, base_prompt)
    for _ in trange(10):
        cand = mutate(BEST[1])
        BEST = max(BEST, score(cand), key=lambda x: x[0])
    
    print("🏆 Best prompt:", BEST[1])
    

    Replace the evaluator with OpenAI Evals or your own rubric to scale this up.

    ──────────────────────────────────────── 6. Choosing a stack ──────────────────────────────────────── • Want quick, no-code? → PromptPerfect / Humanloop.
    • Comfortable with Python, like “compiler” abstraction? → DSPy.
    • Already on LangChain? → Use langchain.evaluation + your own mutate() fn.
    • Need rigorous benchmark, maybe public leaderboard? → OpenAI Evals.
    • Research / publishable experiments? → OPRO or Self-Refine (simple, citeable).

    ──────────────────────────────────────── 7. Tips & gotchas ────────────────────────────────────────

    1. Use different seeds (or even different models) for optimizer vs. grader to reduce confirmation bias.
    2. Keep a held-out dev set of queries; evaluate on random subsample each round to avoid overfitting.
    3. Temperature-annoyance trade-off: higher temp in optimizer yields diverse prompts, but wrap with reduce_repetition=True or RPL/penalties.
    4. Log EVERYTHING (prompt, response, score) – you’ll want winners even when the score plunges later.
    5. Cost control: One iteration = 3 LLM calls (mutate, answer, grade). Batch evals and cache responses with something like LangSmith, Trulens, or simple SQLite.

    Have fun building your perpetual prompt-tuning machine!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.