langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.28k stars 14.74k forks source link

Claude XML parser #9820

Closed grabbou closed 9 months ago

grabbou commented 1 year ago

Feature request

I find StructuredOutputParser to not work that well with Claude. It also takes quite a few tokens to output its format instructions.

It would be great to have a built-in support for using XMLs as a meaning of transportation.

Motivation

Claude supports and works really well with XML tags.

An example output:

When you reply, first find exact quotes in the FAQ relevant to the user's question and write them down word for word inside XML tags. This is a space for you to write down relevant content and will not be shown to the user. Once you are done extracting relevant quotes, answer the question. Put your answer to the user inside XML tags.

As you can see, it works really well providing the answer inline the paragraph. Unlike StructuredOutputParser, we don't have to provide examples, explain the schema as well as ask to wrap the output in the markdown delimiter.

I would personally use something like regular expressions to look and parse the contents inside the tags, not forcing Claude itself to stick to any particular output format (such as "your response must be a valid XML document" etc.).

Your contribution

I would be happy to own this feature and send a PR to TypeScript implementation. I have already written this locally and have tested it to work quite well. Note it is a very rough implementation, as my understanding of the codebase is (at this point) rather limited. I am making my baby steps tho!

I would be happy to pair with someone on the Python side to explain how the things work with Claude.

dosubot[bot] commented 1 year ago

🤖

Thank you for your interest in contributing to LangChain! Your proposed feature of adding built-in support for using XMLs as a means of transportation sounds like a valuable addition to the framework.

It's great to hear that you have already implemented this feature locally and have tested it successfully. Your willingness to send a PR to the TypeScript implementation is much appreciated.

If you would like to pair with someone on the Python side to explain how things work with Claude, I encourage you to reach out to the LangChain community. They will be able to provide guidance and support as you work on your contribution.

Thank you for your dedication and enthusiasm in improving LangChain!


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] commented 9 months ago

Hi, @grabbou! I'm Dosu, and I'm here to help the LangChain team manage our backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you requested built-in support for using XMLs as a means of transportation in the Claude XML parser. You have already implemented a rough version and are willing to contribute to the TypeScript implementation. I have responded, thanking you for your interest and suggesting that you reach out to the LangChain community for guidance and support.

If this issue is still relevant to the latest version of the LangChain repository, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and your contributions to the LangChain project!

Best regards, Dosu