How to Customize the code_output_template and empty_code_output_template in Open Interpreter
The code_output_template and empty_code_output_template settings in Open Interpreter are configurable string templates that determine how code execution results are formatted and presented to the LLM, with {content} serving as the placeholder for actual output.
When using Open Interpreter to execute code locally, the way execution results are communicated back to the language model significantly impacts the conversation flow. The code_output_template and empty_code_output_template attributes control this formatting, allowing you to customize how stdout appears in the LLM context window. This guide explains how to modify these templates using constructor arguments, runtime assignment, or profile configurations.
Understanding the Template System
Open Interpreter uses two distinct templates to handle different execution scenarios. Both are plain strings that support a single {content} placeholder for dynamic substitution.
code_output_template
This template formats output when executed code produces text on stdout. The default value is:
Code output: {content}
What does this output mean / what's next (if anything, or are we done)?
The interpreter substitutes {content} with the captured standard output before sending the message to the LLM.
empty_code_output_template
This template is used when code executes successfully but produces no text output (empty string). The default value is:
The code above was executed on my machine. It produced no text output. what's next (if anything, or are we done?)
This prevents the LLM from waiting indefinitely for output that will never arrive.
Where Templates Are Defined and Processed
Core Definition in core.py
The templates are defined as instance attributes in the OpenInterpreter class constructor at interpreter/core/core.py (lines 70-73). During initialization, the constructor accepts code_output_template and empty_code_output_template as optional keyword arguments and stores them as instance attributes for later use.
Message Conversion Logic
When preparing messages for the LLM, the interpreter performs placeholder substitution in interpreter/core/llm/utils/convert_to_openai_messages.py (lines 97-105). This module checks whether the code produced content:
- If content exists, it formats the string using
code_output_template.replace("{content}", content) - If content is empty, it uses
empty_code_output_templatedirectly
This substitution occurs after code execution but before the message is appended to the conversation history sent to the language model.
Methods to Customize the Templates
You can customize these templates through three primary approaches: constructor arguments, runtime attribute assignment, or profile-based configuration.
Constructor Arguments
Pass custom templates when instantiating OpenInterpreter to set the behavior for the entire session:
from interpreter.core.core import OpenInterpreter
my_interpreter = OpenInterpreter(
code_output_template=(
"🔧 Executed code produced:\n```\n{content}\n```\n"
"What should we do next?"
),
empty_code_output_template=(
"✅ Code ran but printed nothing. "
"Is there anything else you need?"
),
)
my_interpreter.chat("list the files in the current directory")
The constructor arguments map directly to the attributes used later in convert_to_openai_messages.py.
Runtime Attribute Assignment
Modify templates after instantiation to change behavior dynamically during a conversation:
from interpreter import interpreter # uses the pre-instantiated singleton
interpreter.code_output_template = (
"🖥️ Output:\n---\n{content}\n---\n"
"Explain the result or give the next command."
)
interpreter.empty_code_output_template = (
"🤖 No visible output. Ask the user for further instructions."
)
The change takes effect immediately and applies to the next code execution.
Profile-Based Configuration
Create reusable configurations using the terminal interface's profile system. Create a new profile file, such as interpreter/terminal_interface/profiles/defaults/my_custom_profile.py:
# my_custom_profile.py
def apply(interpreter):
interpreter.code_output_template = (
"📊 Here is what the code returned:\n```output\n{content}\n```\n"
"What does this mean?"
)
interpreter.empty_code_output_template = (
"⚪️ The snippet ran silently. What shall we try next?"
)
Then launch the terminal interface with your custom profile:
oi --profile my_custom_profile
Profiles are loaded by the terminal interface (terminal_interface.py), allowing per-LLM or per-project customization without modifying the core interpreter code. The repository includes example overrides in profiles such as qwen at interpreter/terminal_interface/profiles/defaults/qwen.py (lines 21-22).
Practical Template Examples
Using Markdown Formatting
Rich formatting helps the LLM distinguish between code output and instructions:
interpreter.code_output_template = (
"### Code Result\n"
"```text\n{content}\n```\n"
"#### Next step?\n"
"- [ ] Explain the output\n"
"- [ ] Run another command"
)
The LLM receives the markdown and can follow the checklist structure or ask clarifying questions based on the formatted output.
Summary
code_output_templateformats stdout from executed code using a{content}placeholder, whileempty_code_output_templatehandles cases with no output.- Default definitions reside in
interpreter/core/core.py(lines 70-73), with substitution logic ininterpreter/core/llm/utils/convert_to_openai_messages.py(lines 97-105). - Customize templates via constructor arguments for new instances, runtime attribute assignment for dynamic changes, or profile-based configuration for reusable setups in the terminal interface.
- Because templates are plain strings, you can inject markdown, JSON, or additional prompting language to optimize LLM comprehension.
Frequently Asked Questions
What is the difference between code_output_template and empty_code_output_template?
The code_output_template is used when executed code produces text output on stdout, replacing the {content} placeholder with the actual captured output. The empty_code_output_template is used exclusively when code executes successfully but returns an empty string, ensuring the LLM receives confirmation that execution completed rather than waiting indefinitely for output that does not exist.
Can I use multiple placeholders in the templates?
Currently, the Open Interpreter source code only substitutes the {content} placeholder in convert_to_openai_messages.py. While you can include other text or formatting markers in the template strings, only {content} will be dynamically replaced with execution results. Additional custom variables would require modifying the substitution logic in the core source files.
How do I persist template changes across sessions?
To persist custom templates, create a profile file in interpreter/terminal_interface/profiles/defaults/ that defines an apply(interpreter) function setting your preferred templates. Launch the interpreter using oi --profile your_profile_name to automatically load these settings. This approach avoids hardcoding changes into the core library while ensuring consistent behavior across terminal sessions.
Do template changes affect existing conversations?
Template changes only affect code executions that occur after the modification. The substitution happens in convert_to_openai_messages.py immediately after code execution and before the message is appended to the conversation history. Therefore, altering the templates mid-conversation will change how future outputs are formatted, but will not retroactively modify messages already sent to the LLM in the current session.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →