simonw / files-to-prompt

Concatenate a directory full of files into a single prompt for use with LLMs
Apache License 2.0
244 stars 17 forks source link

Add `--xml` flag to structure output for Claude's long context window #15

Open lexh opened 2 months ago

lexh commented 2 months ago

Add --xml flag to structure output for Claude's long context window

Background

Anthropic has provided specific guidelines for optimally structuring prompts to take advantage of Claude's extended context window (up to 200K tokens for Claude 3 models).

In particular, they recommend wrapping long input documents in XML tags to clearly delineate the boundaries between the documents and the rest of the prompt. This allows Claude to more accurately process the information.

Proposal

To better support using files-to-prompt output with Claude, a new --xml flag should be added. When this flag is set, the tool should structure its output like this:

Here are some documents for you to reference for your task:

<documents>
<document path="path/to/file1.txt">
Contents of file1.txt
</document>

<document path="path/to/file2.txt">
Contents of file2.txt
</document>
</documents>

The <documents> and <document> tags clearly separate the file contents from any additional prompt text that may be provided after.

Additional Considerations