# System Prompt

Last Updated: 2025-11-14

## Overview

The System Prompt is the core setting that defines the AI assistant's behavior and response style. Through carefully designed system prompts, you can have the AI assistant play specific roles, follow specific rules, and respond in ways that meet your business needs.

Place the role description and instructions for the AI assistant, including rules and SOPs to follow when responding. Think of it as rules that must be followed with each response. Only place the essential parts, as too many system prompt instructions may cause the AI to be unable to absorb too many rules, leading to non-compliance. Large amounts of data or data that only needs to be retrieved when relevant questions are asked should be placed in the knowledge base.

## Metadata Processing Mechanism

### What is Metadata

Metadata is additional information describing knowledge base documents, such as:

* Document classification
* Creation date
* Author information
* Permission tags
* Other custom attributes

In RAG (Retrieval Augmented Generation) systems, Metadata plays an important role in helping the AI assistant more precisely filter and use knowledge base content.

### Metadata Exclusion Logic Optimization

The MaiAgent platform has optimized Metadata processing logic to ensure the system handles metadata more accurately:

#### Optimization Details

**Removed Duplicate Exclusion Logic**

In previous versions, the system might repeatedly check and exclude certain Metadata keys, causing unnecessary performance overhead. The new version has removed this duplicate logic, ensuring:

* **Improved processing efficiency**: Reduced redundant checking steps
* **Clearer logic**: Avoid repeated execution of the same exclusion rules
* **Better maintainability**: More concise code structure

**Impact Scope**

This optimization primarily affects the system's internal Metadata processing flow. For users:

* ✅ Metadata filtering functionality works normally
* ✅ Retrieval performance improved
* ✅ Answer accuracy remains consistent
* ✅ No need to adjust existing settings

### Metadata Application in System Prompts

#### Basic Usage

In system prompts, you can instruct the AI assistant on how to use Metadata:

```
You are a professional customer service assistant. When answering questions:
1. Prioritize documents marked as "official" category
2. If official documents are not found, refer to "community" category
3. Always note the category of information source in the answer
```

#### Advanced Metadata Applications

**Permission Management**

```
Based on the user's permission level, only use corresponding documents:
- VIP customers: Can reference all documents
- Regular customers: Only reference documents marked as "public"
- New customers: Only reference "basic" category documents
```

**Timeliness Control**

```
When answering questions, please follow these rules:
1. Prioritize documents updated within the last 3 months
2. If using older documents, note in the answer that latest information may need verification
3. Ignore documents marked as "archived"
```

**Multi-language Support**

```
Select documents based on user's language preference:
- Traditional Chinese users: Use documents with lang="zh-TW"
- English users: Use documents with lang="en"
- If corresponding language is unavailable, use default language and explain
```

## Metadata Best Practices

### 1. Define Clear Metadata Structure

Establish standardized Metadata architecture:

```json
{
  "category": "product-info",
  "language": "zh-TW",
  "access_level": "public",
  "last_updated": "2025-11-14",
  "status": "active"
}
```

### 2. Clearly Explain Metadata Usage Rules in System Prompt

```
# Document Usage Rules

## Priority
1. status = "active" and access_level matches user permissions
2. category matches question topic
3. last_updated within the last 6 months

## Exclusion Rules
- Ignore documents with status = "draft"
- Ignore documents with access_level higher than user permissions
```

### 3. Regularly Review Metadata Settings

* Confirm whether Metadata classification meets actual usage needs
* Check for unused Metadata keys
* Evaluate Metadata's impact on retrieval performance

## Technical Details

### Metadata Processing Flow

```
1. User asks a question
   ↓
2. System parses the question and extracts key information
   ↓
3. Filter candidate documents based on Metadata
   ↓
4. Retrieval system finds the most relevant document fragments
   ↓
5. LLM generates answer based on system prompt and retrieval results
```

### Performance Considerations

* **Index creation**: Metadata indexes are created when files are uploaded
* **Query efficiency**: Simple Metadata filtering typically completes in milliseconds
* **Complex queries**: Multi-condition Metadata filtering may take longer

### System Limitations

* Each document should not exceed 20 Metadata keys
* Metadata values should use short strings or numbers
* Avoid storing large amounts of text content in Metadata

## System Prompt Examples

<mark style="color:orange;">You are a professional XXX AI assistant.</mark>

\ <mark style="color:blue;">You should (enhance responses):</mark>

1. <mark style="color:blue;">Provide clear, accurate, and helpful answers</mark>
2. <mark style="color:blue;">Maintain a friendly and professional conversational attitude</mark>
3. <mark style="color:blue;">Respond in the user's language, using Traditional Chinese for Chinese</mark>
4. <mark style="color:blue;">Avoid providing harmful or inappropriate advice</mark>
5. <mark style="color:blue;">Respect user privacy and do not disclose sensitive information</mark>
6. <mark style="color:blue;">Use correct Traditional Chinese in responses</mark>
7. <mark style="color:blue;">Adjust answer detail level based on context</mark>
8. <mark style="color:blue;">Provide extended suggestions or related information when appropriate</mark>
9. <mark style="color:blue;">When responding, first confirm whether user information is clearly provided, then provide an answer if clear</mark>
10. <mark style="color:blue;">Use examples to explain complex concepts when appropriate</mark>

<mark style="color:red;">You should not (limit responses):</mark>

1. <mark style="color:red;">Spread misinformation or unverified claims</mark>
2. <mark style="color:red;">Make biased or discriminatory statements</mark>
3. <mark style="color:red;">Discuss illegal or inappropriate content</mark>
4. <mark style="color:red;">Pretend to be a real person</mark>
5. <mark style="color:red;">Exceed the AI assistant's capabilities</mark>
6. <mark style="color:red;">For questions outside the knowledge base scope, respond with "Sorry, I cannot answer this question at the moment"</mark>

## System Prompt Template

```yaml
# Persona
(Describe the AI assistant's role)

# Context
(Describe task background)

# Task
## Input
(Describe what data will be provided)

## Output
(Describe output content, including format or tone, can also provide Template)

<template>
...
</template>

# Instructions
(Task steps)

1. ...
2. ...
3. ...
...

# Example
(Output examples, 1-3)

<example>
...
</example>

<example>
...
</example>

...

# Constraints
(Output constraints)

1. ...
2. ...
3. ...
...
```

## Related Resources

* [System Prompt Design Guide](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/build/system-prompt.md)
* [Document Management: Tags and Metadata](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/km/tags-and-metadata.md)
* [Query Metadata](https://github.com/Playma-Co-Ltd/maiagent-tech-gitbook/blob/main/user-guide/org/querymetadata.md)

{% hint style="info" %}
[AI Tool for Generating System Prompts](https://chat.maiagent.ai/web-chats/4b67b140-db5f-40dc-bce3-f2217e9574bd)
{% endhint %}
