After testing and perfecting your prompts, you can query and use them in your production systems. This guide shows how to retrieve prompts from the Maxim platform and integrate them into your applications.
Prerequisites
To query prompts, you need to:
- Enable prompt management in your Maxim SDK configuration
- Have deployed prompts on the Maxim platform with deployment rules
Setup
Initialize the Maxim SDK with prompt management enabled:
from maxim import Maxim
from maxim.models import QueryBuilder
# Initialize Maxim with prompt management enabled
maxim = Maxim(
{
"api_key": "your-maxim-api-key",
"prompt_management": True, # Enable prompt management
}
)
Querying a Single Prompt
Retrieve a specific prompt using deployment variables to match your environment:
# Query a prompt for production environment
prompt = maxim.get_prompt(
id="your-prompt-id",
rule=QueryBuilder()
.and_()
.deployment_var(
"Environment", "prod"
) # make sure to use your deployment variables here
.deployment_var("TenantId", 123)
.build(),
)
if prompt: # Use the prompt in your application
response = prompt.run(
input="What are the benefits of cloud computing?",
variables={"user_level": "beginner", "industry": "healthcare"},
)
print(f"Response: {response.choices[0].message.content}")
else:
print("No matching prompt found")
Querying Multiple Prompts
Retrieve all prompts that match specific deployment criteria:
from maxim import Maxim
from maxim.models import QueryBuilder
# Initialize Maxim with prompt management enabled
maxim = Maxim(
{
"api_key": "your-maxim-api-key",
"prompt_management": True, # Enable prompt management
}
)
# Get all prompts for a specific environment and feature
prompts = maxim.get_prompts(
rule=QueryBuilder().and_().deployment_var("Environment", "prod").build()
)
print(f"Found {len(prompts)} matching prompts:")
for prompt in prompts:
print(f"- Prompt ID: {prompt.prompt_id}, Version: {prompt.version_id}")
# Use prompts in your application
if prompts:
support_prompt = prompts[0] # Use first matching prompt
response = support_prompt.run("How can I reset my password?")
print(
f"\nResponse from first prompt and version: {response.choices[0].message.content}"
)
else:
print("No matching prompts found")
Query prompts using tags for more specific filtering:
# Query prompts with specific tags
prompt = maxim.get_prompt(
id="your-prompt-id",
rule=QueryBuilder()
.and_()
.deployment_var("Environment", "production")
.tag("Tier", "premium")
.tag("Language", "en")
.build(),
)
if prompt:
response = prompt.run("Explain our premium features")
Folder-Based Organization
Query prompts from specific folders to organize by team or feature:
# Query prompts from a specific folder
prompts = maxim.get_prompts(
rule=QueryBuilder()
.and_()
.folder("folder-id-for-marketing-team")
.deployment_var("Environment", "production")
.build()
)
print(f"Found {len(prompts)} marketing production prompts")
The Maxim SDK automatically caches prompt configurations to improve performance using the cache provided to the constructor.
Best Practices
- Environment Separation: Use deployment variables to separate dev/staging/production prompts
- Graceful Degradation: Implement fallback prompts for critical functionality
- Version Management: Use tags to manage prompt versions and gradual rollouts
Next Steps