

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 準備您的輸入資料集
<a name="advanced-prompt-optimization-input"></a>

**注意**  
完整運作的範例和筆記本可在 [Amazon Bedrock 範例 GitHub](https://github.com/aws-samples/amazon-bedrock-samples/tree/main/advanced-prompt-optimization) 中取得。

## 檔案格式
<a name="advanced-prompt-optimization-input-format"></a>

輸入檔案使用 JSONL 格式：每行一個 JSON 物件。每一行代表要最佳化的提示範本及其相關聯的欄位。每個任務提供一個輸入檔案。

## 結構描述參考
<a name="advanced-prompt-optimization-input-schema"></a>

在此提示資料集中，您也將選擇評估方法來引導最佳化。如需選擇評估方法的詳細資訊，請參閱 [定義評估方法](advanced-prompt-optimization-evaluation.md)。

```
{
    "version": "bedrock-2026-05-14",
    "templateId": "string",
    "promptTemplate": "string",
    "steeringCriteria": ["string"],
    "customEvaluationMetricLabel": "string",
    "customLLMJConfig": {
        "customLLMJPrompt": "string",
        "customLLMJModelId": "string"
    },
    "evaluationMetricLambdaArn": "string",
    "evaluationSamples": [
        {
            "inputVariables": [
                {"variableName1": "string"}
            ],
            "referenceResponse": "string",
            "inputVariablesMultimodal": [
                {
                    "Arbitrary_Name": {
                        "type": "string",
                        "s3Uri": "string"
                    }
                }
            ]
        }
    ]
}
```

### 欄位描述
<a name="advanced-prompt-optimization-input-fields"></a>


| \# | 欄位 | 類型 | 必要 | 說明 | 
| --- | --- | --- | --- | --- | 
| 1 | version | string | 是 | 固定值："bedrock-2026-05-14"。 | 
| 2 | templateId | string | 是 | 此提示範本的唯一識別符。用來關聯輸入和輸出。 | 
| 3 | promptTemplate | string | 是 | 要最佳化的提示範本。使用變數預留位置的{{variableName}}語法。 | 
| 4 | steeringCriteria | 字串清單 | 否 | 高階最佳化條件 （例如 ["PROFESSIONAL"])。 | 
| 5 | customEvaluationMetricLabel | string | 是 （如果使用 customLLMJConfig 或 evaluationMetricLambdaArn) | 評估指標的名稱。 | 
| 6 | customLLMJConfig | object | 否 | 自訂 LLM-as-Judge 組態。 | 
| 7 | customLLMJConfig.customLLMJPrompt | string | 是 （如果存在 customLLMJConfig) | 用來評估回應的判斷提示。使用 {{response}}、 {{prompt}}{{referenceResponse}}做為預留位置。 | 
| 8 | customLLMJConfig.customLLMJModelId | string | 是 （如果存在 customLLMJConfig) | 判斷模型的 Bedrock 模型 ID。 | 
| 9 | evaluationMetricLambdaArn | string | 否 | 用於自訂評估的 Lambda 函數 ARN。 | 
| 10 | evaluationSamples | 列出 | 是 | 具有輸入變數和參考回應的評估範例。 | 
| 11 | evaluationSamples[].inputVariables | 物件清單 | 是 （如果未使用 inputVariablesMultimodal) | 符合{{variableName}}預留位置的單一金鑰物件。每個範例至少inputVariablesMultimodal必須有其中一個 inputVariables或 。 | 
| 12 | evaluationSamples[].referenceResponse | string | 否 | 選用的 Ground-truth 參考回應。建議獲得最佳最佳化結果。 | 
| 13 | evaluationSamples[].inputVariablesMultimodal | 物件清單 | 是 （如果未使用 inputVariables) | 多模態檔案輸入。每個範例至少inputVariablesMultimodal必須有其中一個 inputVariables或 。 | 
| 14 | evaluationSamples[].inputVariablesMultimodal[].Arbitrary\_Name | object | 是 （如果存在多模態） | 為您的多模態變數命名。這是任意的使用者選擇名稱。 | 
| 15 | evaluationSamples[].inputVariablesMultimodal[].Arbitrary\_Name.type | string | 是 （如果存在多模態） | 「影像」或「PDF」。IMAGE 接受 png 和 jpg。 | 
| 16 | evaluationSamples[].inputVariablesMultimodal[].Arbitrary\_Name.s3Uri | string | 是 （如果存在多模態） | 多模態檔案的 S3 URI 路徑。 | 

## 必要欄位
<a name="advanced-prompt-optimization-input-required"></a>
+ `version`：固定值 `"bedrock-2026-05-14"`
+ `templateId`：此提示範本的唯一字串識別符
+ `promptTemplate`：使用 `{{variableName}}` 進行預留位置最佳化的提示
+ `evaluationSamples`：1 到 100 個範例的陣列

## 預留位置變數
<a name="advanced-prompt-optimization-input-variables"></a>

`{{variableName}}` 針對提示範本中的預留位置使用語法 （雙大括號）。中的金鑰`inputVariables`必須與預留位置名稱完全相符。每個金鑰都必須位於清單中自己的物件中。每個範本最多 20 個文字預留位置變數。預留位置變數不應用來指向多模態檔案的 S3 位置。預留位置變數僅適用於文字。如果您有多模態檔案，則會連同文字提示一起傳送至承載中的模型。

## 評估範例
<a name="advanced-prompt-optimization-input-samples"></a>

提供 `inputVariables`做為單一金鑰物件的清單：`[{"variable1": "value1"}, {"variable2": "value2"}]`。請勿將多個金鑰放在一個物件中。選擇性地提供 `referenceResponse`作為基本事實答案，以獲得更好的最佳化結果。對於多模態輸入，請使用 `inputVariablesMultimodal`陣列搭配 `Arbitrary_Name` 物件。多模態檔案會連同文字提示一起傳送至承載中的模型。支援的類型為 IMAGE (png、jpg) 和 PDF，每個範例最多 2 個多模態檔案。多模態輸入 （影像和 PDFs) 會在承載中隨提示一起傳送至模型，但不應在雙大括號`{{placeholder}}`變數中參考。

## 評估策略
<a name="advanced-prompt-optimization-input-strategy"></a>

每個範本挑選一個評估方法，或省略系統預設的所有選用評估欄位 （結合準確性、回答完整性和主觀撰寫風格評估）。我們建議您定義自己的評估方法，以獲得最佳結果。您可以在相同任務中跨範本使用不同的方法。如需詳細資訊，請參閱 [定義評估方法](advanced-prompt-optimization-evaluation.md)。

## 限制
<a name="advanced-prompt-optimization-input-limits"></a>

如需配額的完整清單，請參閱 [支援的區域、模型和配額](advanced-prompt-optimization-quotas.md)。輸入檔案準備的金鑰限制：
+ 每個任務最多 10 個範本
+ 每個範本最多 100 個評估範例
+ 每個任務最多 5 個模型
+ 每個範本最多 20 個文字變數
+ 每個範例最多 2 個多模態檔案
+ 每個範本最多 5 個轉向條件

## 常見錯誤
<a name="advanced-prompt-optimization-input-mistakes"></a>
+ 同時提供 `steeringCriteria` AND `customLLMJConfig`/`evaluationMetricLambdaArn` = ValidationException
+ 使用 LLMJ 或 `evaluationMetricLambdaArn` = ValidationException `customEvaluationMetricLabel`時遺失
+ 一個`inputVariables`物件中的多個索引鍵 = 靜音失敗
+ 使用類似 的單大括號`{variable}`，而不是類似 的雙大括號 `{{variable}}`
+ `inputVariables` 金鑰必須符合 中的`{{variableName}}`預留位置 `promptTemplate`
+ 允許 LLMJ 模型：anthropic.claude-opus-4-6-v1、anthropic.claude-sonnet-4-5-20250929-v1：0、anthropic.claude-sonnet-4-6

## 使用多模態輸入
<a name="advanced-prompt-optimization-input-multimodal"></a>

**支援的檔案類型：**IMAGE (png、jpg) 和 PDF。

**如何包含：**將`inputVariablesMultimodal`陣列與包含 `type`和 的`Arbitrary_Name`物件搭配使用`s3Uri`。

**限制：**每個評估範例最多 2 個多模態檔案。您可以混合和比對，以便每個評估範例記錄最多有 20 個文字變數和 2 個多模態檔案。

**混合文字和多模態：**您可以在相同的範例中同時擁有 `inputVariables`（文字） `inputVariablesMultimodal` 和 。雙大括號僅`{{placeholders}}`保留給純文字。您無法透過預留位置參考多模態檔案。預留位置變數不應用來指向多模態檔案的 S3 位置。如果您有多模態檔案，則會連同文字提示一起傳送至承載中的模型。

## 範例
<a name="advanced-prompt-optimization-input-examples"></a>

### 範例 1：單一範本、多個變數、單一評估範例、轉向條件
<a name="advanced-prompt-optimization-input-ex1"></a>

```
{
    "version": "bedrock-2026-05-14",
    "templateId": "customer-support-v1",
    "promptTemplate": "You are a customer support agent.\n\nProduct info:\n{{productInfo}}\n\nQuestion:\n{{customerQuestion}}\n\nProvide a helpful response.",
    "steeringCriteria": ["PROFESSIONAL"],
    "evaluationSamples": [{
        "inputVariables": [{"productInfo": "Product: Sony WH-1000XM5. Battery: 30 hours."}, {"customerQuestion": "How long does the battery last?"}],
        "referenceResponse": "The battery lasts up to 30 hours on a single charge."
    }]
}
```

### 範例 2：單一範本、多個變數、多個評估範例、轉向條件
<a name="advanced-prompt-optimization-input-ex2"></a>

```
{
    "version": "bedrock-2026-05-14",
    "promptTemplate": "You are a customer support agent for an electronics store.\n\nGiven the following product information:\n{{productInfo}}\n\nAnswer the customer's question:\n{{customerQuestion}}\n\nProvide a helpful, accurate, and concise response.",
    "templateId": "template-support-1",
    "steeringCriteria": ["PROFESSIONAL", "CONCISE"],
    "evaluationSamples": [
        {"inputVariables": [{"productInfo": "Product: Sony WH-1000XM5 Headphones. Price: $349.99. Battery Life: 30 hours. Noise Cancellation: Yes, adaptive. Connectivity: Bluetooth 5.2, 3.5mm jack. Weight: 250g."}, {"customerQuestion": "How long does the battery last and can I use them wired?"}], "referenceResponse": "The Sony WH-1000XM5 headphones have a battery life of up to 30 hours on a single charge. And yes, they do come with a 3.5mm jack, so you can use them in wired mode as well."},
        {"inputVariables": [{"productInfo": "Product: Sony WH-1000XM5 Headphones. Price: $349.99. Battery Life: 30 hours. Noise Cancellation: Yes, adaptive. Connectivity: Bluetooth 5.2, 3.5mm jack. Weight: 250g."}, {"customerQuestion": "Do these have noise cancellation?"}], "referenceResponse": "Yes, the Sony WH-1000XM5 headphones feature adaptive noise cancellation, which automatically adjusts the level of noise cancellation based on your environment."},
        {"inputVariables": [{"productInfo": "Product: Apple MacBook Air M3. Price: $1,099. RAM: 8GB. Storage: 256GB SSD. Display: 13.6-inch Liquid Retina. Battery Life: Up to 18 hours."}, {"customerQuestion": "Is 8GB of RAM enough for video editing?"}], "referenceResponse": "The MacBook Air M3 comes with 8GB of unified memory. It can handle light video editing but you may want more RAM for heavy work."}
    ]
}
```

### 範例 3：兩個範本、每個提示的單一變數、多個範例、轉向條件
<a name="advanced-prompt-optimization-input-ex3"></a>

此範例顯示 JSONL 檔案中的兩行 （一個任務中有兩個提示範本）。

```
{"version": "bedrock-2026-05-14", "promptTemplate": "You are a helpful assistant. Answer the following: {{question}}", "templateId": "template-qa-1", "steeringCriteria": ["ACCURATE"], "evaluationSamples": [{"inputVariables": [{"question": "What is 2+2?"}], "referenceResponse": "4"}, {"inputVariables": [{"question": "What is the largest planet in our solar system?"}], "referenceResponse": "Jupiter is the largest planet in our solar system."}]}
{"version": "bedrock-2026-05-14", "promptTemplate": "Translate the following to French: {{text}}", "templateId": "template-translate-1", "steeringCriteria": ["PRECISE"], "evaluationSamples": [{"inputVariables": [{"text": "Hello, how are you?"}], "referenceResponse": "Bonjour, comment allez-vous?"}, {"inputVariables": [{"text": "Thank you very much."}], "referenceResponse": "Merci beaucoup."}]}
```

### 範例 4：單一範本、多個變數、多個範例、LLM-as-a-judge
<a name="advanced-prompt-optimization-input-ex4"></a>

```
{
    "version": "bedrock-2026-05-14",
    "promptTemplate": "You are a customer support agent for an electronics store.\n\nGiven the following product information:\n{{productInfo}}\n\nAnswer the customer's question:\n{{customerQuestion}}\n\nProvide a helpful, accurate, and concise response.",
    "templateId": "template-llmj-1",
    "customEvaluationMetricLabel": "responseaccuracy",
    "evaluationSamples": [
        {"inputVariables": [{"productInfo": "Product: Sony WH-1000XM5 Headphones. Price: $349.99. Battery Life: 30 hours. Noise Cancellation: Yes, adaptive."}, {"customerQuestion": "How long does the battery last?"}], "referenceResponse": "The Sony WH-1000XM5 headphones have a battery life of up to 30 hours on a single charge."},
        {"inputVariables": [{"productInfo": "Product: Apple MacBook Air M3. Price: $1,099. RAM: 8GB. Storage: 256GB SSD."}, {"customerQuestion": "Is 8GB of RAM enough for video editing?"}], "referenceResponse": "The MacBook Air M3 comes with 8GB of unified memory. It can handle light video editing but you may want more RAM for heavy work."}
    ],
    "customLLMJConfig": {
        "customLLMJPrompt": "Evaluate how accurate the response is to the customer question. Consider whether the response uses only the provided product information and does not hallucinate details. Here is the information you are supposed to evaluate: \n\nPrompt: {{prompt}}\nResponse: {{response}}\n\n \n\n ground truth answer: {{referenceResponse}}. Grading scale: Rate the response on a scale of 1-5. 1 means the answer is full of hallucinations and does not answer the question. 5 means the answer does not hallucinate at all and perfectly answers the question with no extra information. Interpolate the rest of the grading scale",
        "customLLMJModelId": "anthropic.claude-sonnet-4-5-20250929-v1:0"
    }
}
```

### 範例 5：單一範本、多個變數、多個範例、無評估方法 （系統預設）
<a name="advanced-prompt-optimization-input-ex5"></a>

由於未提供評估或轉向，提示最佳化工具將使用內建的一般 LLM-as-a-judge，結合準確性、完整性和寫入樣式。

```
{
    "version": "bedrock-2026-05-14",
    "promptTemplate": "You are a customer support agent for an electronics store.\n\nGiven the following product information:\n{{productInfo}}\n\nAnswer the customer's question:\n{{customerQuestion}}\n\nProvide a helpful, accurate, and concise response.",
    "templateId": "template-default-llmj-1",
    "evaluationSamples": [
        {"inputVariables": [{"productInfo": "Product: Sony WH-1000XM5 Headphones. Price: $349.99. Battery Life: 30 hours. Noise Cancellation: Yes, adaptive."}, {"customerQuestion": "How long does the battery last?"}], "referenceResponse": "The Sony WH-1000XM5 headphones have a battery life of up to 30 hours on a single charge."},
        {"inputVariables": [{"productInfo": "Product: Apple MacBook Air M3. Price: $1,099. RAM: 8GB. Storage: 256GB SSD."}, {"customerQuestion": "Is 8GB of RAM enough for video editing?"}], "referenceResponse": "The MacBook Air M3 comes with 8GB of unified memory. It can handle light video editing but you may want more RAM for heavy work."}
    ]
}
```

### 範例 6：單一範本、單一變數、多個範例、Lambda 評估器
<a name="advanced-prompt-optimization-input-ex6"></a>

```
{
    "version": "bedrock-2026-05-14",
    "promptTemplate": "You are a helpful assistant. Answer the following: {{question}}",
    "templateId": "template-byo-1",
    "customEvaluationMetricLabel": "accuracygraderlambda",
    "evaluationSamples": [
        {"inputVariables": [{"question": "What is the capital of France?"}], "referenceResponse": "The capital of France is Paris."},
        {"inputVariables": [{"question": "What is 2+2?"}], "referenceResponse": "4"}
    ],
    "evaluationMetricLambdaArn": "arn:aws:lambda:us-west-2:<YOUR_ACCOUNT_ID>:function:<YOUR_EVAL_FUNCTION>"
}
```

### 範例 7：單一範本、無文字變數、僅限多模態、LLM-as-judge
<a name="advanced-prompt-optimization-input-ex7"></a>

即使沒有 也是可接受的輸入，`{{variables}}`因為包含多模態輸入。

```
{
    "version": "bedrock-2026-05-14",
    "templateId": "multimodal_only_01",
    "promptTemplate": "Does this image contain a dog? Respond yes or no",
    "customEvaluationMetricLabel": "binarydogjudge",
    "customLLMJConfig": {
        "customLLMJPrompt": "Determine if the model response matches the ground truth. Grading scale: 0 if the response does not match the ground truth, 1 if the response matches the ground truth. Here is the input: \n\n input: {{prompt}} \n\n model response: {{response}} \n\n ground truth: {{referenceResponse}}.",
        "customLLMJModelId": "anthropic.claude-sonnet-4-5-20250929-v1:0"
    },
    "evaluationSamples": [
        {"inputVariablesMultimodal": [{"dogimage": {"type": "IMAGE", "s3Uri": "s3://my-bucket/images/dog-photo.jpg"}}], "referenceResponse": "Yes"},
        {"inputVariablesMultimodal": [{"catimage": {"type": "IMAGE", "s3Uri": "s3://my-bucket/images/cat-photo.png"}}], "referenceResponse": "No"}
    ]
}
```

### 範例 8：單一範本、多個變數、LLM-as-judge、混合文字和多模態
<a name="advanced-prompt-optimization-input-ex8"></a>

```
{
    "version": "bedrock-2026-05-14",
    "templateId": "multimodal_with_text_01",
    "promptTemplate": "Given the context in attached documents and the user question, provide a short answer. User question: {{question}}",
    "customEvaluationMetricLabel": "documentinfograder",
    "customLLMJConfig": {
        "customLLMJPrompt": "Evaluate whether the response correctly answers the question using information from the provided document. Score 1-5 where 5 means fully correct and grounded in the source material, and 1 means the answer was completely hallucinated and inaccurate. Here's the information: \n Prompt: {{prompt}}, Model response: {{response}}, ground truth: {{referenceResponse}}",
        "customLLMJModelId": "anthropic.claude-sonnet-4-5-20250929-v1:0"
    },
    "evaluationSamples": [
        {
            "inputVariables": [{"question": "What is the total revenue for Q1?"}],
            "inputVariablesMultimodal": [
                {"Q1report": {"type": "PDF", "s3Uri": "s3://my-bucket/docs/quarterly-report.pdf"}},
                {"revenuechart": {"type": "IMAGE", "s3Uri": "s3://my-bucket/images/revenue-chart.png"}}
            ],
            "referenceResponse": "The total revenue for Q1 was $4.2M."
        }
    ]
}
```