Im writing a prompt to a llm, and want the output to be a list that I'll be able to…
- User
Im writing a prompt to a llm, and want the output to be a list that I'll be able to easily parse. What output format should I ask the llm to provide?
- Assistant
If your goal is easy parsing, you should ask the LLM to return the output in a strict, machine-readable format. The two most common and robust choices are:
- JSON – Best for structured data, works well with most programming languages. Example prompt addition:
"Return the output only as a valid JSON array of strings, with no additional text." Expected output:
jsonCopyEdit["item1", "item2", "item3"]
- Newline-separated plain text – Simple to read and split by \n. Example prompt addition:
"Return the output as a plain list, one item per line, no numbering, no extra text." Expected output:
nginxCopyEdititem1 item2 item3
When to pick which:
Use JSON if you need type safety, nesting, or more structured info (e.g., dictionaries with keys).
Use newline-separated text if you just need a quick, human-readable flat list.
If you want, I can give you a ready-to-use prompt template that guarantees well-formatted JSON output from an LLM.
- User
I thought to ask something like this: "Enclose each of the evaluation prompt between the tags “[Start of Evaluation Prompt]” and “[End of Evaluation Prompt]"
- Assistant
That can work, but it’s a bit more brittle than JSON if you plan to parse automatically — you’d need to use regex or string-splitting to extract between those tags, and if the LLM messes up the tags even slightly, your parser might break. If you go with your tag approach, I’d suggest:
Use a unique token sequence unlikely to appear naturally in text (e.g., <<START_PROMPT>> instead of [Start of Evaluation Prompt]).
Make sure you explicitly instruct the LLM not to include anything outside the tags.
Add a clear format instruction in your prompt, like:
Output each evaluation prompt as follows: pgsqlCopyEdit<<START_PROMPT>> [Your evaluation prompt here] <<END_PROMPT>>
Do not include any text outside these tags. Separate each block with a blank line.
Example output: pgsqlCopyEdit<<START_PROMPT>> Describe the impact of renewable energy on rural economies. <<END_PROMPT>>
<<START_PROMPT>> Explain quantum entanglement in simple terms. <<END_PROMPT>>
If you need bulletproof parsing, JSON is still safer — but your tag format is fine if you just want something human-readable and fairly easy to split. I can rewrite your tag-based format so it’s LLM-error-resistant if you want.
- User
please do that
- Assistant
Here’s a more LLM-error-resistant version of your tag-based format:
Prompt instruction to the LLM
You are to produce a list of evaluation prompts. Each evaluation prompt must be enclosed exactly between the tags <<START_PROMPT>> and <<END_PROMPT>>. Formatting rules (follow exactly):
Use the tag <<START_PROMPT>> on a line by itself before each prompt.
Write the prompt text on one or more lines.
Use the tag <<END_PROMPT>> on a line by itself after each prompt.
Put a blank line between each prompt block.
Do not add numbering, bullet points, or any text outside these tags.
Example format: pgsqlCopyEdit<<START_PROMPT>> Your evaluation prompt here. <<END_PROMPT>>
<<START_PROMPT>> Another evaluation prompt here. <<END_PROMPT>>
Example output from the LLM pgsqlCopyEdit<<START_PROMPT>> Describe the potential effects of artificial intelligence on job markets in the next decade. <<END_PROMPT>>
<<START_PROMPT>> Explain the differences between classical and quantum computing. <<END_PROMPT>>
This way:
You have exact markers for regex or .split() parsing.
- User
please help me write the me the code for parsing
- Assistant
Here’s a simple Python snippet that will extract all the prompts between your <<START_PROMPT>> and <<END_PROMPT>> tags: pythonCopyEditimport re
def extract_prompts(text): # Regex to capture text between tags, allowing multiline prompts pattern = r"<<START_PROMPT>>\s*(.?)\s<<END_PROMPT>>" return re.findall(pattern, text, re.DOTALL)
Example usage
llm_output = """ <<START_PROMPT>> Describe the potential effects of artificial intelligence on job markets in the next decade. <<END_PROMPT>>
<<START_PROMPT>> Explain the differences between classical and quantum computing. <<END_PROMPT>> """
prompts = extract_prompts(llm_output) for i, p in enumerate(prompts, start=1): print(f"Prompt {i}:", p)
How it works:
re.DOTALL makes the . match across multiple lines, so prompts can be multiline.
\s* trims extra spaces and newlines inside the tags.
The findall() call returns a list of prompt strings in order.
If you want, I can also give you a more fault-tolerant parser that works even if the LLM accidentally adds extra spaces, capitalizes the tags differently, or puts junk before/after. That can be handy if you’re working with imperfect model outputs.