With the Snippet tool

The Humanloop Snippet tool supports managing common text 'snippets' (or 'passages', or 'chunks') that you want to reuse across your different prompts. A Snippet tool acts as a simple key/value store, where the key is the name of the common re-usable text snippet and the value is the corresponding text.

For example, you may have some common persona descriptions that you found to be effective across a range of your LLM features. Or maybe you have some specific formatting instructions that you find yourself re-using again and again in your prompts.

Instead of needing to copy and paste between your editor sessions and keep track of which projects you edited, you can instead inject the text into your prompt using the Snippet tool.


Create and use a Snippet Tool

Prerequisites

  1. A Humanloop account - you can create one by going to our sign up page.
  2. Be on a paid plan - your organization has been upgraded from the Free tier.
  3. You already have a project created - if not, please pause and first follow our project creation guides.

🚧

Paid feature

The Snippet tool is not available for the Free tier. Please contact us if you wish to learn more about our Enterprise plan

To create and use a snippet tool, follow the following steps:

  1. Navigate to the tools tab in your organisation and select the Snippet tool card.

  1. Name the tool assistant-personalities and give it a description Useful assistant personalities.
  2. In the initial box add helpful-assistant and give it a value of You are a helpful assistant. You like to tell jokes and if anyone asks your name is Sam.
  3. Let's add another key-value pair, so press the Add a key/value pair button and add a new key of grumpy-assistant and give it a value of You are a grumpy assistant. You rarely try to help people and if anyone asks your name is Freddy..

  1. Press Create Tool. Now your Snippets are set up, you can use it to populate strings in your prompt templates across your projects.
  2. Navigate to the Editor of your previously created project.
  3. In the Chat Templates section, delete the default assistants' string, and add {{ assistant-personalities(key) }}.

πŸ“˜

Tool syntax: {{ (key) }}

Double curly bracket syntax is used to call a tool in the editor. Inside the curly brackets you put the tool name, e.g. {{ <tool-name>(key) }}.

  1. Enter the key helpful-assistant. The tool requires an input value to be provided for the key. When adding the tool an inputs field will appear in the top right of the editor where you can specify your key.
  2. Press the Run button in the editor to start the chat with the LLM. You can see the response of the LLM, as well as, see the key you previously defined add in the Chat on the right.

  1. Change the key to grumpy-assistant.

🚧

The snippet will only render (or update) in the preview after running the chat

If you want to see the corresponding snippet to the key you either need to first run the conversation to fetch the string and see it in the preview.

  1. Ask the LLM, I'm a customer and need help solving this issue. Can you help?'. You should see a grumpy response from "Freddy" now.
  2. If you have a specific key you would like to hardcode in the prompt, you can define it using the literal key value: {{ <your-tool-name>("key") }}, so in this case it would be {{ assistant-personalities("grumpy-assistant") }}. Delete the grumpy-assistant field and add it into your chat template.
  3. If you're happy with you're grumpy assistant, Save your model config.

The Snippet tool is particularly useful because you can define passages of text once in a Snippet tool and reuse them across multiple prompts, without needing to copy/paste them and manually keep them all in sync. Editing the values in your tool allows the changes to automatically propagate to the model configs when you update them, as long as the key is the same.

🚧

Changing a snippet value can change a model configs behaviour

Since the values for a Snippet are saved on the tool, not the model config, changing the values (or keys) defined in your Snippet tools could affect the relative model config behaviour. This could be exactly what you intend, however caution should still be used make sure the changes are expected.


What’s Next

Explore our other tools such as the Google or Pinecone Search. If you have other ideas for helpful integrations please reach out and let us know.