Skip to main content
Write File functions allow AI assistants to create or overwrite files with content, using built-in security controls that restrict access to designated directories.
Caution: File OverwriteWrite File functions will overwrite existing files without warning. Use Edit File functions for safer modifications to existing files.

Configuration

template
required
Path to the file to write. Can be absolute or relative to the working directory (config/extended_openai_conversation/).
template
required
Content to write to the file. Can include Jinja2 templates for dynamic content generation.
array
Optional list of additional allowed directories (as templates). By default, only the working directory is allowed.

Working Directory

The default working directory is config/extended_openai_conversation/.

Examples

Write File

Custom Allowed Directories

Extend allowed directories beyond the default workspace. The allow_dir parameter adds additional directories where files can be written.
allow_dir accepts templates with access to variables like {{ config_dir }}:

Return Value

On success:
On error:

Error Types

  • Access denied: File path is outside allowed directories
  • Permission error: Insufficient permissions to write file
  • No such file or directory: Parent directory doesn’t exist
  • Other errors: Encoding issues, disk full, etc.

Dynamic Content Generation

Write File functions support Jinja2 templates in the content field:

Generate YAML Configuration

Generate JSON Data

Generate Python Script

Use Cases

Note Taking

Save user notes, reminders, and documentation

Configuration Generation

Generate automation configs, scripts, templates

Data Export

Export sensor data, logs, or analysis results

Report Generation

Create markdown, CSV, or text reports

Common Patterns

Append Timestamp to Filename

Write Multiple Lines

Write CSV Data

Conditional Content

Security

Files must be within allowed directories. By default:
  • /config/extended_openai_conversation/ (working directory)
Additional directories can be added via allow_dir.
Paths are resolved to absolute paths and validated. Attempts to use ../ to escape allowed directories will be blocked.
Write File overwrites existing files without confirmation. Use Edit File for safer modifications.
Parent directories are not automatically created. The parent directory must exist before writing a file. Use bash functions if you need to create directories:

Best Practices

1

Validate before overwriting

Check if file exists before overwriting (use composite function):
2

Use descriptive filenames

Include timestamps or identifiers in filenames:
3

Handle encoding properly

Always use UTF-8 text. For special characters, ensure proper escaping:
4

Organize files in subdirectories

Use subdirectories to organize files (ensure they exist first):

Troubleshooting

The target path is outside allowed directories. Either:
  • Write to the workspace (/config/extended_openai_conversation/)
  • Add the target directory to allow_dir
The parent directory doesn’t exist. Create it first:
Check:
  • File permissions on the parent directory
  • Available disk space
  • SELinux or AppArmor policies (in container environments)

FAQ

Existing files are overwritten without warning. There is no backup or confirmation. Use Edit File for safer modifications to existing files.
No. Parent directories must exist before writing a file. Use bash functions to create directories if needed.
There’s no explicit limit, but very large content (>10MB) may cause memory issues. For large files, consider using bash functions with streaming:
No. Write File always overwrites. To append, use bash functions:

Next Steps

Read File

Read file contents

Edit File

Safely modify existing files

Bash Functions

Advanced file operations