Skip to main content
Read File functions allow AI assistants to read file contents from the filesystem with built-in security controls that restrict access to designated directories.

Configuration

template
required
Path to the file to read. Can be absolute or relative to the working directory (config/extended_openai_conversation/).
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

Read File

Custom Allowed Directories

Extend allowed directories beyond the default workspace. The allow_dir parameter adds additional directories where files can be read.
allow_dir accepts templates, so you can use variables like {{ config_dir }}:

Return Value

On success:
On error:

Error Types

  • File not found: The specified file doesn’t exist
  • Not a file: The path points to a directory
  • File too large: File exceeds 1 MB size limit
  • Access denied: File is outside allowed directories
  • Permission error: Insufficient permissions to read file

File Size Limit

Files larger than 1 MB (1,048,576 bytes) are blocked to prevent memory issues:
For large files, consider using bash functions with head, tail, or grep to read specific parts:

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 against allowed directories. Attempts to use ../ to escape allowed directories will be blocked:
Files over 1 MB are automatically rejected to prevent memory exhaustion.
Files are read with UTF-8 encoding. Binary files may not be read correctly.

Use Cases

Configuration Review

Read and analyze Home Assistant configuration files

Log Analysis

Read log files to diagnose issues

Data Files

Access JSON, YAML, CSV, or text data files

Script Review

Read automation scripts and templates

Common Patterns

Read YAML Configuration

Read and Parse JSON

Search File Content

Examples

Read Multiple Files

To read multiple files, use a composite function that loops through each file, or create separate function calls for each file.

Read with Error Handling

Best Practices

1

Validate file paths

Always validate that requested files are appropriate to read:
2

Handle errors gracefully

Check for errors in the response and provide helpful feedback:
3

Be mindful of file size

Large files (>1MB) are blocked. For large files, use bash functions to read portions:
4

Use appropriate allowed directories

Only add directories to allow_dir that the AI should legitimately access:

Troubleshooting

The file is outside allowed directories. Either:
  • Move the file to the workspace (/config/extended_openai_conversation/)
  • Add the file’s directory to allow_dir
  • Use an absolute path to /config/ if appropriate
The file exceeds 1 MB. Options:
  • Use bash functions to read portions (head, tail, grep)
  • Split the file into smaller chunks
  • Process the file externally and save results to a smaller file
Check:
  • File path is correct (relative to working directory)
  • File exists at the specified location
  • Path separators are correct (use / on all platforms)
Files must be UTF-8 encoded. For binary files or other encodings, consider using bash functions:

FAQ

No. Read File functions use UTF-8 text encoding. For binary files, use bash functions:
1 MB (1,048,576 bytes). This limit prevents memory issues when processing large files.
Yes, by adding directories to allow_dir. However, the default workspace and /config are always available.

Next Steps

Write File

Write content to files

Edit File

Edit files with find-and-replace

Bash Functions

More flexible file operations