Prompt Blueprints are central to PromptLayer’s architecture, enabling you to work seamlessly with multiple LLM providers in a single format. They abstract provider-specific details, allowing you to switch between LLMs without modifying your code.

Prompt Blueprint is a model-agnostic and standardized schema that PromptLayer uses to store prompts.

Accessing the Prompt Blueprint

Instead of accessing the raw LLM response via response["raw_response"], it’s recommended to use the standardized response["prompt_blueprint"]. This ensures consistency across different providers.

response = promptlayer_client.run(
    prompt_name="ai-poet",
    input_variables={'topic': 'food'},
)

print(response["prompt_blueprint"]["prompt_template"]["messages"][-1]["content"][0]["text"])

With this approach, you can update from one provider to another (e.g., OpenAI to Anthropic) without any code changes.

Placeholder Messages

Placeholder Messages are a powerful feature that allows you to inject messages into a prompt template at runtime. By using the placeholder role, you can define placeholders within your prompt template that can be replaced with full messages when the prompt is executed.

For more detailed information on Placeholder Messages, including how to create and use them, please refer to our dedicated Placeholder Messages Documentation page.

Running a Template with Placeholders

When running a prompt that includes placeholders, you need to supply the messages that will replace the placeholders in the input variables.

response = promptlayer_client.run(
    prompt_name="template-name",
    input_variables={
        "fill_in_message": [
            {
                "role": "user",
                "content": [{"type": "text", "text": "My age is 29"}],
            },
            {
                "role": "assistant",
                "content": [{"type": "text", "text": "What a wonderful age!"}],
            }
        ]
    },
)

Note: The messages provided must conform to the Prompt Blueprint format.

Prompt Blueprint Message Format

Each message in a Prompt Blueprint should be a dictionary with the following structure:

  • role: The role of the message sender (user, assistant, etc.).
  • content: A list of content items, where each item has:
    • type: The type of content (text, image_url, etc.).
    • text: The text content (if type is text).

Example Message

{
    "role": "user",
    "content": [{"type": "text", "text": "Hello, how are you?"}],
}

Tools and Function Calling

This section demonstrates how to handle function calling within Prompt Blueprints.

def execute_function(name, args):
    return "Success"

messages = [
    {
        "role": "user",
        "content": [{
            "type": "text",
            "text": "Create an index.html file"
        }]
    }
]

response = pl_client.run(
    prompt_name="builder",
    input_variables={
        'messages': messages
    },
)
prompt_blueprint = response['prompt_blueprint'] or {}
prompt_template = prompt_blueprint.get('prompt_template', {})
prompt_template_messages = prompt_template.get('messages', [])
last_message = prompt_template_messages[-1]

for tool_call in last_message.get('tool_calls', []):
    if tool_call['type'] == "function":
        function_name = tool_call['function']['name']
        function_args = json.loads(tool_call['function']['arguments'])
        # Replace this with your actual function execution
        function_response = execute_function(function_name, function_args)
        prompt_template_messages.append({
            "role": "tool",
            "content": [{
                "type": "text",
                "text": function_response
            }],
            "tool_call_id": tool_call['id']
        })

response = pl_client.run(
    prompt_name="builder",
    input_variables={
        'messages': prompt_template_messages
    },
)

print(response)

Multi-Modal Variables

The image_variable attribute allows you to dynamically insert a list of images into prompt template messages.

The image_variable is nested within the message content. The type and image_url are required fields specifying the type of content and the URL of the image, respectively. The image_url needs to be blank and is there for type requirements. The image_variable is the name of the list of images to be dynamically inserted.

{
    "role": "user",
    "content": [
        {
            "type": "image_url",
            "image_url": {"url": ""},
            "image_variable": "images_to_insert"
        }
    ]
}

When defining a prompt template, you can specify an image_variable to dynamically include images in your messages.

Running with Image Variables

response = pl_client.run(
    prompt_name="image-prompt",
    input_variables={
        "image_urls": [
            "https://example.com/image1.jpg",
            "https://example.com/image2.jpg"
        ]
    },
)

print(response)
Notice that the image_urls is a list of strings