SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2309.08532 · ICLR · 2023

EvoPrompt: Connecting LLMs with Evolutionary Algorithms Yields Powerful Prompt Optimizers

Rui Wang, Xu Tan, Junliang Guo, Jiang Bian, Guoqing Liu, Kaitao Song, Yujiu Yang, Qingyan Guo, Bei Li

arXiv · PDF · Open in the Atlas

Code that ran

11 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 2 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 8 failures of our instrument; 2 no recorded run), measured 2026-11-23; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2309.08532.json · badge: /api/ran/2309.08532.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
beeevita/EvoPrompt community
Papers with Code archive
11 ran · 2 no recorded run
FunctionStatusWhere it lives
batchify Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("b330c6d185528db2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

# The function batchify takes data and batch_size
# It iterates through data using len() and slicing
# So data needs to support len() and indexing

# Create a simple list of data items
data = [
    torch.randn(4),
    torch.randn(4),
    torch.randn(4),
    torch.randn(4),
    torch.randn(4),
]

batch_size = 2

ARGS = {
    "data": data,
    "batch_size": batch_size,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list — a list output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
evaluate_optimized_prompt Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("f287013a24f6555f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import tempfile
import os

torch.manual_seed(0)

# Create a temporary directory and data file
temp_dir = tempfile.mkdtemp()
data_file = os.path.join(temp_dir, 'test_data.txt')

# Write sample data to the file
with open(data_file, 'w') as f:
    f.write('sample text one\t0\n')
    f.write('sample text two\t1\n')
    f.write('sample text three\t0\n')

# Mock evaluator class
class MockEvaluator:
    def __init__(self):
        self.verbalizers = {0: 'negative', 1: 'positive'}
        self.test_src = ['text1', 'text2']
        self.test_tgt = ['negative', 'positive']
    
    def forward(self, prompt, eval_src, eval_tgt):
        # Return mock scores
        return {
            'scores': [0.5, 0.7, 0.85]
        }

# Mock args class
class MockArgs:
    def __init__(self):
        self.task = 'cls'
        self.test_file = data_file

# Create mock objects
evaluator = MockEvaluator()
args = MockArgs()

# Create output file path
output_file = os.path.join(temp_dir, 'output.txt')

# Define population and pop_marks
population = [
    'What is the sentiment? It is',
    'Classify the text as'
]

pop_marks = [0.75, 0.65]

ARGS = {
    'population': population,
    'pop_marks': pop_marks,
    'out_path': output_file,
    'evaluator': evaluator,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_numbers Ran
ran, honoured the contract we drafted
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("76fda09860d6a6ba")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re
import string

def extract_numbers(string):
    return [int(num) for num in re.findall('\\d+', string)][0]

# The function takes a single parameter 'string' which should be a string
# It uses re.findall to extract all digit sequences and returns the first one as an int

ARGS = {
    "string": "The answer is 42 and the year is 2024"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_seconds Ran
ran, honoured the contract we drafted
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("d6d67571db47df2d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

ARGS = {
    "text": "The task takes 30 second to complete",
    "retried": 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
form_request Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("c160c6c484af61e4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Setup arguments for form_request function
data = "What is the capital of France?"
type_davinci = "text-davinci-003"
type_chat = "gpt-4"

kwargs_empty = {}
kwargs_with_temp = {"temperature": 0.7}

# Test case 1: davinci type
ARGS = {
    "data": data,
    "type": type_davinci,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_final_prompt Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("cb966a71519c6a02")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

def get_final_prompt(text):
    parts = text.split('<prompt>')
    if len(parts) > 1:
        prompt = parts[-1].split('</prompt>')[0]
        prompt = prompt.strip()
        return prompt
    else:
        if text.startswith('"') and text.endswith('"'):
            text = text[1:-1]
        return text

# Test case 1: text with <prompt> tags
text_with_tags = 'some prefix <prompt>  This is the final prompt  </prompt> some suffix'

# Test case 2: text with quotes
text_with_quotes = '"This is a quoted prompt"'

# Test case 3: plain text without tags or quotes
plain_text = 'This is plain text'

# We'll use the first test case as the main argument
ARGS = {
    'text': text_with_tags
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
k_init_pop Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("2d3025cc9c9fc3eb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import random
import torch

torch.manual_seed(0)

# The function takes:
# - initial_mode: a string indicating which selection mode
# - init_population: a list/sequence of items to select from
# - k: an integer for the number of items to select

# Create a simple init_population with distinct items
init_population = [
    {"id": 0, "score": 0.9},
    {"id": 1, "score": 0.8},
    {"id": 2, "score": 0.7},
    {"id": 3, "score": 0.6},
    {"id": 4, "score": 0.5},
    {"id": 5, "score": 0.4},
    {"id": 6, "score": 0.3},
    {"id": 7, "score": 0.2},
]

ARGS = {
    "initial_mode": "topk",
    "init_population": init_population,
    "k": 4,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
llm_query Ran
ran; our contract draft was wrong, not the code
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("0ef65ffd26166327")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import openai
from unittest.mock import Mock, MagicMock

# Mock the OpenAI client to avoid actual API calls
mock_client = Mock()

# Mock response for ChatCompletion
mock_chat_response = {
    'choices': [
        {'message': {'content': 'This is a mock response from GPT.'}}
    ]
}

# Mock response for Completion (davinci)
mock_completion_response = {
    'choices': [
        {'text': ' This is a mock completion response.'}
    ]
}

# Patch openai methods
openai.ChatCompletion.create = Mock(return_value=mock_chat_response)
openai.Completion.create = Mock(return_value=mock_completion_response)

# Test data
test_data_string = "What is the capital of France?"
test_data_list = [
    "What is the capital of France?",
    "What is the capital of Germany?",
    "What is the capital of Italy?"
]

# Config dictionary
config = {
    'temperature': 0.7,
    'top_p': 0.95
}

# Define ARGS for the llm_query function
ARGS = {
    'data': test_data_string,
    'client': mock_client,
    'type': 'gpt-3.5-turbo',
    'task': True,
    'config': config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
load_cls_data Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("94a4deb83a99ae36")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 2, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
import os

# Create a temporary file with test data
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("hello world\t0\n")
temp_file.write("foo bar\t1\n")
temp_file.close()

# Define verbalizers mapping class indices to labels
verbalizers = {
    0: "positive",
    1: "negative"
}

# Define sample indices to read specific lines
sample_indices = [0, 1]

ARGS = {
    "verbalizers": verbalizers,
    "data_path": temp_file.name,
    "sample_indices": sample_indices
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
paraphrase Ran
ran on a synthesized input
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("5db86cda527c983b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import openai
from unittest.mock import Mock, MagicMock, patch

# Mock the OpenAI client and API responses
mock_client = Mock()

# Create a mock OpenAI module that doesn't require actual API keys
mock_openai = Mock()
mock_openai.ChatCompletion.create = Mock(return_value={
    'choices': [{'message': {'content': 'A paraphrased variation of the instruction.'}}]
})
mock_openai.Completion.create = Mock(return_value={
    'choices': [{'text': 'A paraphrased variation of the instruction.'}]
})

# Patch openai module
import sys
sys.modules['openai'] = mock_openai

# Test with a single sentence (string)
single_sentence = "Please summarize the main ideas in the document."

# Test with a list of sentences
sentence_list = [
    "Explain the concept of machine learning.",
    "What is the importance of data preprocessing?"
]

# Model type - using turbo (ChatCompletion) to avoid actual API calls
model_type = "gpt-3.5-turbo"

# Additional kwargs for the llm_query function
config_kwargs = {
    "temperature": 0.7,
    "top_p": 0.9
}

ARGS = {
    "sentence": single_sentence,
    "client": mock_client,
    "type": model_type,
    "kwargs": config_kwargs
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
read_lines Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("0e0098507bc5fbe9")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
import os

# Create a temporary file with some test content
temp_file = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt')
temp_file.write("line 0\n")
temp_file.write("line 1\n")
temp_file.write("line 2\n")
temp_file.write("line 3\n")
temp_file.write("line 4\n")
temp_file.close()

# Define arguments for the function
ARGS = {
    'file_': temp_file.name,
    'sample_indices': [0, 2, 4]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Evoluter Not yet run
unverified (harvested, no recorded run)
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("57c7f6a20eb98788")
How it ran

no invocation recorded.

GAEvoluter Not yet run
unverified (harvested, no recorded run)
beeevita/EvoPrompt/evoluter.py
code served (permissive licence) · get_code("c8d2f9365df18753")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 13 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large Language Models (LLMs) excel in various tasks, but they rely on carefully crafted prompts that often demand substantial human effort. To automate this process, in this paper, we propose a novel framework for discrete prompt optimization, called EVOPROMPT, which borrows the idea of evolutionary algorithms (EAs) as they exhibit good performance and fast convergence. To enable EAs to work on discrete prompts, which are natural language expressions that need to be coherent and human-readable, we connect LLMs with EAs. This approach allows us to simultaneously leverage the powerful language processing capabilities of LLMs and the efficient optimization performance of EAs. Specifically, abstaining from any gradients or parameters, EVOPROMPT starts from a population of prompts and iteratively generates new prompts with LLMs based on the evolutionary operators, improving the population based on the development set. We optimize prompts for both closed-and open-source LLMs including GPT-3.5 and Alpaca, on 31 datasets covering language understanding, generation tasks, as well as BIG-Bench Hard (BBH) tasks. EVOPROMPT significantly outperforms human-engineered prompts and existing methods for automatic prompt generation (e.g., up to 25% on BBH). Furthermore, EVOPROMPT demonstrates that connecting LLMs with EAs creates synergies, which could inspire further research on the combination of LLMs and conventional algorithms. Our code is available at https://github.com/beeevita/EvoPrompt.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2309.08532")
get_code_for_paper("2309.08532")
have("2309.08532")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2309.08532.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2309.08532.svg)](https://syntology.ai/paper/2309.08532)

Connect an agent — have() is free.