Claude Enterprise custom system prompts
Quick answer
Use the
system parameter in the client.messages.create call with the Claude Enterprise model to set custom system prompts. This allows you to define the assistant's behavior and context explicitly for your use case.PREREQUISITES
Python 3.8+Anthropic API key with Enterprise accesspip install anthropic>=0.20
Setup
Install the anthropic Python SDK and set your Anthropic Enterprise API key as an environment variable.
- Install SDK:
pip install anthropic - Set environment variable:
export ANTHROPIC_API_KEY='your_enterprise_key'(Linux/macOS) orsetx ANTHROPIC_API_KEY "your_enterprise_key"(Windows)
pip install anthropic output
Collecting anthropic Downloading anthropic-0.20.0-py3-none-any.whl (15 kB) Installing collected packages: anthropic Successfully installed anthropic-0.20.0
Step by step
Use the system parameter to provide your custom system prompt when calling client.messages.create with the Claude Enterprise model. This example shows a simple prompt that instructs Claude to act as a helpful assistant.
import os
import anthropic
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
system_prompt = "You are a helpful assistant specialized in enterprise workflows."
user_message = "Explain how to set custom system prompts in Claude Enterprise."
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=512,
system=system_prompt,
messages=[{"role": "user", "content": user_message}]
)
print(response.content[0].text) output
You can set custom system prompts in Claude Enterprise by passing your instructions in the 'system' parameter of the messages.create call. This defines the assistant's behavior and context for your session.
Common variations
You can customize system prompts for different scenarios, such as stricter tone, domain-specific knowledge, or multi-turn conversations. Also, you can use async calls or adjust max_tokens and temperature for varied responses.
import asyncio
import os
import anthropic
async def main():
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
system_prompt = "You are a strict compliance officer."
user_message = "Summarize the latest compliance regulations."
response = await client.messages.acreate(
model="claude-3-5-sonnet-20241022",
max_tokens=300,
system=system_prompt,
messages=[{"role": "user", "content": user_message}]
)
print(response.content[0].text)
asyncio.run(main()) output
The latest compliance regulations require strict adherence to data privacy laws, including GDPR and CCPA, with mandatory audits and reporting.
Troubleshooting
- If you receive an authentication error, verify your
ANTHROPIC_API_KEYenvironment variable is set correctly and has Enterprise access. - If the system prompt is ignored, ensure you are using the
systemparameter (not a message role) and the correct modelclaude-3-5-sonnet-20241022. - For unexpected output, try adjusting
max_tokensor adding more detailed instructions in the system prompt.
Key Takeaways
- Use the
systemparameter to set custom system prompts with Claude Enterprise. - Always specify the Enterprise model
claude-3-5-sonnet-20241022for best compatibility. - Set your Anthropic API key in the environment variable
ANTHROPIC_API_KEYbefore running code. - Async calls are supported for scalable integration in Python applications.
- Adjust prompt detail and token limits to control response quality and length.