System Messages and Prompts
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
Generative AI with Foundry: Mastering System Messages and Prompts
Introduction: The Architecture of AI Communication
In the landscape of modern data platforms, Palantir Foundry has emerged as a central hub for integrating artificial intelligence into enterprise operations. When we talk about "Generative AI with Foundry," we are not merely discussing the integration of Large Language Models (LLMs); we are discussing the precise orchestration of how these models interact with your proprietary data. The most critical lever you have in this orchestration is the design of prompts and system messages.
A prompt is essentially the instruction set you provide to an LLM to elicit a specific output. A system message, on the other hand, acts as the "persona" or the "operating manual" for the model. It defines the boundaries, the tone, the constraints, and the objective of the conversation. If you think of an LLM as a highly capable but directionless intern, the system message is the job description and the rulebook, while the prompt is the specific task assignment. Mastering these two elements is the difference between an AI tool that produces reliable, actionable insights and one that hallucinates, wanders off-topic, or violates data security policies.
Understanding how to craft these instructions within the Foundry ecosystem is vital because your models are often operating on sensitive, complex, and highly structured datasets. Unlike generic chatbot applications, Foundry-based AI needs to adhere to strict ontological constraints, security labels, and business logic. By the end of this lesson, you will understand how to build resilient prompt structures that ensure your AI implementations are predictable, safe, and highly effective.
1. The Anatomy of a Prompt: Beyond Simple Questions
Many beginners approach prompting as if they are typing a search query into a browser. However, interacting with an LLM within an enterprise environment requires a more structured approach. A high-quality prompt in Foundry usually consists of several distinct layers: the Context, the Instruction, the Constraints, and the Output Format.
The Context Layer
The context layer provides the model with the necessary background information to perform its task. In Foundry, this often involves pulling data from the Ontology. You might be asking the model to analyze a supply chain disruption, so the context would include current inventory levels, shipment status, and supplier reliability scores. Without this context, the model is forced to rely on its general training data, which will inevitably be outdated or irrelevant to your specific business reality.
The Instruction Layer
This is the "what." It should be an imperative, clear, and unambiguous command. Instead of saying "Tell me about this inventory," a better instruction is "Analyze the provided inventory data and identify the top three items at risk of stockout within the next 48 hours." The more specific the instruction, the less room there is for the model to interpret the task in ways you did not intend.
The Constraints Layer
Constraints are the guardrails. They tell the model what not to do. Examples include "Do not mention competitor names," "Only use the provided data," or "If the answer is not in the data, state that you do not have enough information." In a corporate environment, these constraints are the primary defense against misinformation and security breaches.
The Output Format Layer
Finally, you must define the shape of the answer. Do you need a JSON object for an API integration? Do you need a bulleted list for a manager’s email? Do you need a Markdown table for a report? By explicitly requesting a format, you make the AI’s output immediately usable in downstream Foundry workflows without requiring manual cleanup.
Callout: Prompt Engineering vs. System Messaging While they are often used together, they serve different functions. A system message is persistent; it sets the global behavior of the model for the duration of the session. A prompt is transient; it is the specific input for a single turn in the conversation. Think of the system message as the model's "character" and the prompt as the "script" for the current scene.
2. Designing Effective System Messages
The system message is the foundational instruction set that governs the model's behavior. In Foundry, this is often configured at the model-deployment level or the application-agent level. A well-designed system message should cover three key areas: Identity, Scope, and Tone.
Defining the Identity
Who is the AI? Is it a data analyst, a customer support assistant, or a supply chain optimizer? Defining the identity helps the model adopt the correct vocabulary and perspective. For instance, an AI acting as a "Supply Chain Analyst" will prioritize throughput and lead times, whereas a "Customer Support Assistant" will prioritize empathy and resolution speed.
Setting the Scope
What is the model allowed to discuss? You should explicitly define the boundaries of the model's expertise. If your Foundry app is designed to help users navigate HR policies, the system message should specify: "You are an HR policy assistant. You only answer questions regarding the company handbook and internal procedures. Do not provide legal advice or financial planning assistance."
Establishing the Tone
Tone dictates how the information is delivered. In a professional setting, the tone should generally be objective, concise, and helpful. You can specify constraints like "Use professional language," "Avoid jargon," or "Keep responses under three sentences."
Example of a Robust System Message
You are a Lead Logistics Coordinator for [Company Name].
Your objective is to provide objective, data-driven insights based on the provided Foundry Ontology datasets.
- Always cite the specific object types or properties you are referencing.
- If data is missing or ambiguous, state that clearly rather than guessing.
- Maintain a professional, concise tone.
- Do not speculate on future market trends beyond what is represented in the provided data.
- If a user asks for information outside of logistics or inventory management, politely decline and redirect them.
3. Practical Implementation: Code and Configuration
When implementing these concepts within Foundry, you will often interact with the Model APIs. While the UI provides a convenient way to set these, understanding the underlying JSON structure is crucial for automation and version control.
The API Structure
When sending a request to an LLM via the Foundry API, you typically structure your payload as an array of message objects. Each object has a role (system, user, or assistant) and content.
{
"messages": [
{
"role": "system",
"content": "You are a data assistant that outputs findings in Markdown tables."
},
{
"role": "user",
"content": "Compare the performance of Project A and Project B based on the latest quarterly data."
}
],
"parameters": {
"temperature": 0.2,
"max_tokens": 500
}
}
Explanation of Parameters
- Role: System: This defines the persistent instruction set.
- Role: User: This is the input provided by the end-user in the Foundry application.
- Temperature: This is a critical hyperparameter. A lower temperature (e.g., 0.1 to 0.3) makes the model more deterministic and focused, which is ideal for data analysis and factual retrieval. A higher temperature (e.g., 0.7 to 0.9) encourages creativity, which is better for brainstorming or content generation.
- Max Tokens: This limits the length of the response, helping you manage costs and performance latency.
Note: Always set your temperature to a lower value when working with enterprise data. High-temperature settings introduce randomness that, while creative, is often undesirable when accuracy and consistency are the primary requirements of your business process.
4. Best Practices for Prompt Engineering
Developing prompts is an iterative process. You will rarely get the perfect result on the first try. Use the following best practices to refine your approach.
The "Few-Shot" Prompting Technique
One of the most effective ways to improve model performance is to provide examples of the desired input-output pair within the prompt. This is called "Few-Shot" prompting.
Example: "Translate the following supply chain status updates into a simplified status code. Input: 'The shipment is currently stuck at the port due to customs clearance issues.' -> Output: DELAY_CUSTOMS Input: 'The raw materials have arrived at the warehouse and are being processed.' -> Output: RECEIVED_PROCESSING Input: 'The truck has left the facility and is currently in transit.' -> Output: IN_TRANSIT Input: [Current User Input] -> Output:"
Chain-of-Thought Prompting
If you are asking the model to perform a complex task, ask it to "think" before it answers. By adding the phrase "Let's think step by step," you encourage the model to break down the reasoning process, which significantly reduces errors in logical tasks.
Handling Data Privacy and Security
Foundry is built on a foundation of strict security. When crafting prompts, ensure that your instructions reinforce these security boundaries.
- Data Minimization: Only pass the data necessary for the task in the prompt. Do not dump an entire database table if the model only needs to compare two specific rows.
- PII Scrubbing: Ensure that your prompt generation logic automatically strips Personally Identifiable Information (PII) before it reaches the LLM, unless strictly necessary and authorized.
5. Common Pitfalls and How to Avoid Them
Even experienced developers fall into common traps when implementing AI in a production environment. Being aware of these will save you significant debugging time.
The "Vague Instruction" Trap
Vague prompts lead to vague answers. If you ask, "Analyze the data," the model will provide a generic summary. Instead, be specific: "Identify the three most significant outliers in the 'Cost' property for the last 30 days."
The "Over-Prompting" Trap
Sometimes, developers try to cram too many instructions into a single system message. This can lead to "instruction drift," where the model forgets earlier instructions in favor of later ones. Keep your system messages concise and focused on the most important constraints.
Ignoring Model Latency
Generative AI is not instantaneous. If you are building a user-facing dashboard in Foundry, consider how the prompt length affects response time. Longer prompts take longer to process. Optimize your prompts to be as short as possible while still maintaining the necessary clarity.
Failing to Validate Outputs
Never assume that the AI output is 100% accurate. Implement validation layers in your Foundry workflows. If the model is supposed to return a JSON object, use a script to parse that JSON and verify its schema before displaying it to the user or writing it back to the Ontology.
Warning: Never allow an LLM to perform destructive actions (like deleting data or modifying object properties) without human-in-the-loop verification. Even the most well-prompted model can make mistakes or misinterpret an instruction. Always require a human to review and approve AI-generated changes before they are committed to your production data environment.
6. Comparison: Deterministic vs. Generative Approaches
It is helpful to know when to use an LLM and when to use traditional deterministic code.
| Scenario | Use Deterministic Code (Functions/SQL) | Use Generative AI (LLMs) |
|---|---|---|
| Data Retrieval | High (Exact values needed) | Low (Prone to hallucination) |
| Data Summarization | Low | High (Natural language capability) |
| Complex Reasoning | Low | High (Can navigate unstructured text) |
| Rule Enforcement | High (Hardcoded logic) | Low (Interpretive) |
| Format Conversion | Medium | High (Flexible parsing) |
Use this table as a mental framework. If you are asking, "What is the sum of these numbers?", use a Foundry Function or SQL. If you are asking, "Why did these numbers decrease compared to last month?", that is a perfect task for an LLM.
7. Step-by-Step: Building an AI-Powered Workflow
Let’s walk through the process of creating a simple AI-powered insight generator in Foundry.
Step 1: Define the Objective We want an AI agent that monitors our "Sales Order" objects and flags orders that are likely to be delayed based on their "Status" and "Delivery Date."
Step 2: Construct the System Message "You are a Sales Operations assistant. Your task is to review Sales Order objects. If the status is 'Processing' and the delivery date is within 3 days, flag the order as 'High Risk' and provide a brief justification based on the order notes."
Step 3: Prepare the Data Context In your Foundry workflow (e.g., in a Workshop module or a Python transform), write the logic to fetch only the relevant objects.
# Pseudo-code for data retrieval
orders = Objects.search().sales_order().filter(status == 'Processing')
context_data = serialize_for_ai(orders)
Step 4: Execute the Prompt
Pass the context_data and your system message to the LLM.
# Executing the request
response = foundry_ai.chat(
system_message=system_message,
user_message=f"Review these orders: {context_data}"
)
Step 5: Parse and Display Take the response and store it in a new "Risk Assessment" property within your Ontology, or display it directly in a Workshop widget.
8. Advanced Strategies: The Role of Retrieval-Augmented Generation (RAG)
In many Foundry use cases, the data you need to analyze is too large to fit into a single prompt. This is where Retrieval-Augmented Generation (RAG) becomes essential. Instead of sending all your data to the model, you use a search mechanism to retrieve only the relevant snippets of information.
How RAG Works
- Embedding: Your documents or object descriptions are converted into vectors (numerical representations of meaning) and stored in a vector database within Foundry.
- Querying: When a user asks a question, you convert that question into a vector.
- Retrieval: The system finds the most similar vectors in your database.
- Augmentation: You inject those specific, relevant snippets into the prompt as "context."
- Generation: The model answers the question using only the retrieved context.
This drastically improves the accuracy of the model and reduces the likelihood of hallucinations, as the model is effectively "reading" your documents before answering.
9. Troubleshooting and Iterative Improvement
When your AI implementation isn't behaving as expected, follow this systematic troubleshooting process:
- Check the Input Data: Is the data being passed to the prompt clean and formatted correctly? Garbage in, garbage out applies to LLMs as much as any other system.
- Analyze the System Message: Is the system message too broad? Try tightening the constraints.
- Test the Temperature: If the model is being too creative or inconsistent, lower the temperature.
- Evaluate the Prompt Length: If you are truncating context, the model will miss information. Ensure your retrieval strategy is providing the most relevant chunks.
- Human-in-the-loop Review: Look at the "failed" cases. Are there patterns? Do the failures happen when the user asks specific types of questions? Use this feedback to refine your prompt templates.
10. Summary and Key Takeaways
Implementing Generative AI in Foundry is a disciplined practice of communication and constraint management. By treating the LLM as a sophisticated tool that requires clear instructions rather than a magic box, you can build powerful, reliable applications.
Key Takeaways:
- Structure Matters: Always segment your prompts into Context, Instruction, Constraints, and Output Format. This modularity makes your prompts easier to test and iterate upon.
- System Messages are Guardrails: Use the system message to define the model’s identity, scope, and tone. This is your primary tool for ensuring the AI stays within business boundaries.
- Deterministic vs. Generative: Use traditional code for calculations and factual retrieval; use Generative AI for reasoning, synthesis, and unstructured data analysis.
- Low Temperature for High Accuracy: When working with enterprise data, keep your temperature settings low to ensure consistency and prevent unnecessary creative "hallucinations."
- Few-Shot Prompting is Powerful: Providing clear examples of desired output is the fastest way to improve model accuracy for complex or specialized tasks.
- Security is Paramount: Always assume the model needs to be constrained. Never give it the ability to perform destructive actions without human oversight.
- Iterative Development: Treat prompt engineering like software development. Version your prompts, test them against a set of known inputs, and refine them based on real-world feedback.
By mastering these principles, you move from simply "using" AI to effectively "engineering" AI solutions that provide measurable value within your organization. The goal is not to have an AI that can answer anything, but an AI that answers the right things, in the right way, every single time.
Continue the course
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons