Custom Instructions - Mem0

What are Custom Instructions?

Custom instructions are natural language guidelines that let you define exactly what Mem0 should include or exclude when creating memories from conversations. This gives you precise control over what information is extracted, acting as smart filters so your AI application only remembers what matters for your use case.

Basic Setup

Python

# Set instructions for your project
client.project.update(custom_instructions="Your guidelines here...")

# Retrieve current instructions
response = client.project.get(fields=["custom_instructions"])
print(response["custom_instructions"])

JavaScript

// Set instructions for your project
await client.project.update({ customInstructions: "Your guidelines here..." });

// Retrieve current instructions
const response = await client.project.get({ fields: ["customInstructions"] });
console.log(response.customInstructions);

Best Practice Template

Structure your instructions using this proven template:

Your Task: [Brief description of what to extract]

Information to Extract:
1. [Category 1]:
   - [Specific details]
   - [What to look for]

2. [Category 2]:
   - [Specific details]
   - [What to look for]

Guidelines:
- [Processing rules]
- [Quality requirements]

Exclude:
- [Sensitive data to avoid]
- [Irrelevant information]

Advanced Techniques

Conditional Processing

Handle different conversation types with conditional logic:

Python

advanced_prompt = """
Extract information based on conversation context:

IF customer support conversation:
- Issue type, severity, resolution status
- Customer satisfaction indicators

IF sales conversation:
- Product interests, budget range
- Decision timeline and influencers

IF onboarding conversation:
- User experience level
- Feature interests and priorities

Always exclude personal identifiers and maintain professional context.
"""

client.project.update(custom_instructions=advanced_prompt)

Testing Your Instructions

Always test your custom instructions with real message examples:

Python

# Test with sample messages
messages = [\
    {"role": "user", "content": "I'm having billing issues with my subscription"},\
    {"role": "assistant", "content": "I can help with that. What's the specific problem?"},\
    {"role": "user", "content": "I'm being charged twice each month"}\
]

# Add the messages and check extracted memories
result = client.add(messages, user_id="test_user")
memories = client.get_all(filters={"AND": [{"user_id": "test_user"}]})

# Review if the right information was extracted
for memory in memories:
    print(f"Extracted: {memory['memory']}")

Best Practices

Do

Don’t

Common Issues and Solutions

Issue Solution
Instructions too long Break into focused categories, keep concise
Missing important data Add specific examples of what to capture
Capturing irrelevant info Strengthen exclusion rules and be more specific
Inconsistent results Clarify guidelines and test with more examples