Advanced Sampling Prompt
π¨βπΌ Now that you've wired up basic sampling, it's time to make your prompt
have the LLM do something actually useful! Instead of just asking for a generic
response, you'll craft a prompt that enables the model to suggest relevant tags
for a new journal entry.
Here's what you'll do:
- Update your sampling request to provide the LLM with structured information: the new journal entry, its current tags, and all existing tags in the system.
- Change the user message to send this data as JSON (
application/json
), not plain text. - Write a clear, detailed system prompt that instructs the LLM to make a list of suggested tags that are relevant to the entry and not already applied. Make certain it's instructed on the format of the response.
- Increase the
maxTokens
to allow for a longer, more detailed response. - Test and iterate on your prompt! Try pasting the example JSON into your favorite LLM playground and see how it responds. Refine your instructions until you get the output you want.
Development workflow
π¦ You can use the JSON below to test your prompt:
- Write your prompt into the LLM chat
- Let it respond (It'll probably ask you to provide the JSON)
- Paste the JSON below into the chat and let it respond again
- Evaluate the response (make sure it's in the right format)
- Repeat in new chats until you're happy with the prompt/response
{
"entry": {
"id": 6,
"title": "Day at the Beach with Family",
"content": "Spent the whole day at the beach with the family and it couldn't have been better. The kids were totally absorbed in building a massive sandcastleβcomplete with towers, moats, and even a seaweed flag. We played catch, flew a kite, and waded into the water until our fingers turned into prunes. Rebecca and I went on a shell hunt and found a few keepers. Lunch was sandy PB&Js and watermelon under a big striped umbrella. We stayed until sunset, which painted the sky with ridiculous pinks and oranges. Everyone was sun-tired and happy. Grateful for days like this.",
"mood": "grateful",
"location": "beach",
"weather": "sunny",
"isPrivate": 0,
"isFavorite": 1,
"createdAt": 1746668878,
"updatedAt": 1746668878,
"tags": [{ "id": 1, "name": "Family" }]
},
"currentTags": [
{
"id": 1,
"name": "Family",
"description": "Spending time with family members",
"createdAt": 1746666966,
"updatedAt": 1746666966
}
],
"existingTags": [
{
"id": 1,
"name": "Family",
"description": "Spending time with family members",
"createdAt": 1746666966,
"updatedAt": 1746666966
},
{
"id": 2,
"name": "Outdoors",
"description": "Entries about being outside in nature or open spaces",
"createdAt": 1746667900,
"updatedAt": 1746667900
},
{
"id": 3,
"name": "Exercise",
"description": "Physical activity or movement",
"createdAt": 1746668000,
"updatedAt": 1746668000
},
{
"id": 4,
"name": "Food",
"description": "Eating, meals, or anything food-related",
"createdAt": 1746668001,
"updatedAt": 1746668001
}
]
}
This step will help you practice prompt engineering for structured outputs, and
show you how to use the full power of MCP's sampling API for real-world tasks.