Version control zod schema prompts for tool calling

Karthik Kalyanaraman

Cofounder and CTO

Nov 15, 2024

Introduction

We are excited to announce that Langtrace now supports storing and version controlling zod schema prompts. This means you can store zod schema prompts with in Langtrace and fetch it directly into your code, update versions, deploy a new version or roll back to an older version directly from Langtrace

Usage Instructions

  1. Create a new project in Langtrace and go to the Prompts tab. Click on the “Create Prompt” button to create a new prompt.

  2. Paste the Zod schema in the “Prompt” field. You can define the schema for the tool calling in the Zod format. This schema will be automatically converted to JSON schema which is accepted by the OpenAI spec for tool calling.

  3. Once you have created a prompt, you can make it available by clicking the “Go Live” button. This will make the prompt available for use in your applications by default when you fetch it using the SDK. When fetched, the schema will be converted to JSON schema and can be directly used for tool calling.


  4. Use the prompt in your application by fetching it using the SDK.

import json
from openai import OpenAI
from langtrace_python_sdk import get_prompt_from_registry

# Initialize OpenAI client
openai = OpenAI(api_key='sk-<YOUR_API_KEY>')

# Function to make the API call
def make_tool_call():
    response = get_prompt_from_registry('<Prompt Registry ID>')
    function_params = json.loads(response['value'])
    completion = openai.chat.completions.create(
        model='gpt-3.5-turbo',
        messages=[
            {
                'role': 'system',
                'content': 'You are a helpful assistant that can use various tools.'
            },
            {
                'role': 'user',
                'content': 'Place an order for 3 units of product 1234'
            }
        ],
        functions=[
            {
                'name': 'order_product',
                'description': 'Place an order for a product',
                'parameters': function_params
            }
        ]
    )

    print(completion)


You can also fetch a specific version of the prompt by passing the version number in the options. And you can get the “Prompt Registry ID” from the Langtrace UI. That’s it! You have successfully created and versioned a zod schema in Langtrace. You can now use this schema in your applications and easily manage and reuse it across your projects.

For more information check out our docs here - https://docs.langtrace.ai/features/manage_zod_schema#manage-zod-schema-for-tool-calling

Useful Resources

Ready to try Langtrace?

Try out the Langtrace SDK with just 2 lines of code.

Ready to deploy?

Try out the Langtrace SDK with just 2 lines of code.

Want to learn more?

Check out our documentation to learn more about how langtrace works

Join the Community

Check out our Discord community to ask questions and meet customers