Custom Instructions - Mem0

Custom Instructions for Mem0

Custom instructions let you decide exactly which facts Mem0 records from a conversation. Define a focused prompt, give a few examples, and Mem0 will add only the memories that match your use case.

You’ll use this when…

Prompts that are too broad cause unrelated facts to slip through. Keep instructions tight and test them with real transcripts.

The custom_fact_extraction_prompt parameter has been renamed to custom_instructions. If you are upgrading from an older version, update your configuration accordingly.


Feature Anatomy

Prompt Blueprint

  1. State the allowed fact types.
  2. Include short examples that mirror production messages.
  3. Show both empty ([]) and populated outputs.
  4. Remind the model to return JSON with a facts key only.

Configure It

Write the Custom Prompt

Python

custom_instructions = """
Please only extract entities containing customer support information, order details, and user information.
Here are some few shot examples:

Input: Hi.
Output: {"facts" : []}

Input: The weather is nice today.
Output: {"facts" : []}

Input: My order #12345 hasn't arrived yet.
Output: {"facts" : ["Order #12345 not received"]}

Input: I'm John Doe, and I'd like to return the shoes I bought last week.
Output: {"facts" : ["Customer name: John Doe", "Wants to return shoes", "Purchase made last week"]}

Input: I ordered a red shirt, size medium, but received a blue one instead.
Output: {"facts" : ["Ordered red shirt, size medium", "Received blue shirt instead"]}

Return the facts and customer information in a json format as shown above.
"""

TypeScript

const customInstructions = `
Please only extract entities containing customer support information, order details, and user information.
Here are some few shot examples:

Input: Hi.
Output: {"facts" : []}

Input: The weather is nice today.
Output: {"facts" : []}

Input: My order #12345 hasn't arrived yet.
Output: {"facts" : ["Order #12345 not received"]}

Input: I am John Doe, and I would like to return the shoes I bought last week.
Output: {"facts" : ["Customer name: John Doe", "Wants to return shoes", "Purchase made last week"]}

Return the facts and customer information in a json format as shown above.
`;

Keep example pairs short and mirror the capitalization, punctuation, and tone you see in real user messages.


See It in Action

Example: Order Support Memory

Python

m.add("Yesterday, I ordered a laptop, the order id is 12345", user_id="alice")

TypeScript

await memory.add("Yesterday, I ordered a laptop, the order id is 12345", { userId: "user123" });

Output

{
  "results": [
    {"memory": "Ordered a laptop", "event": "ADD"},
    {"memory": "Order ID: 12345", "event": "ADD"},
    {"memory": "Order placed yesterday", "event": "ADD"}
  ]
}

The output contains only the facts described in your prompt, each stored as a separate memory entry.

Example: Irrelevant Message Filtered Out

Python

m.add("I like going to hikes", user_id="alice")

TypeScript

await memory.add("I like going to hikes", { userId: "user123" });

Output

{
  "results": []
}

Empty results show the prompt successfully ignored content outside your target domain.


Best Practices

  1. Be precise: Call out the exact categories or fields you want to capture.
  2. Show negative cases: Include examples that should produce [] so the model learns to skip them.
  3. Keep JSON strict: Avoid extra keys; only return facts to simplify downstream parsing.
  4. Version prompts: Track prompt changes with a version number so you can roll back quickly.
  5. Review outputs regularly: Spot-check stored memories to catch drift early.