Benedikt Droste Claude Opus 4.5 commited on
Commit ·
2d1ab1a
1
Parent(s): 82df8d4
Improve summarization prompt clarity and robustness
Browse files- Add guardrails for custom instructions to ignore unrelated requests
- Clarify xml_tags output format as list of objects
- Ensure XML tags are well-distributed across sections
- Add rule to avoid concluding phrases like "Overall" or "In summary"
- Add refusal handling for meaningless content
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -276,25 +276,35 @@ def build_prompt(
|
|
| 276 |
|
| 277 |
custom_section = ""
|
| 278 |
if custom_instruction.strip():
|
| 279 |
-
custom_section = f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
|
| 281 |
return f"""You are a professional summarizer, following all given instructions with the utmost care.
|
|
|
|
| 282 |
<text>
|
| 283 |
{tagged_text}
|
| 284 |
</text>
|
|
|
|
| 285 |
# Output Format
|
| 286 |
The output must be in JSON format with the following structure:
|
| 287 |
1. A "structure" string containing your thoughts about the content and structure of the summary
|
| 288 |
-
2. An "xml_tags" list containing
|
|
|
|
| 289 |
3. A "summary" string containing the actual summary with inline XML tag references
|
|
|
|
| 290 |
# Instructions
|
| 291 |
-
1. Start by thinking about and explaining the structure and content of your summary. Select {num_tags} XML tags from the tagged text that capture the most significant data and facts.
|
| 292 |
-
2. Begin with an executive summary introducing
|
| 293 |
3. Structure the summary in coherent paragraphs. Every paragraph should contain at least one XML tag reference.
|
| 294 |
4. Reference XML tags inline in square brackets (e.g., [<a1b2c3d4>]) immediately after the statement they support.
|
| 295 |
5. Each XML tag must appear exactly once in the summary.
|
| 296 |
-
6. Avoid a concluding paragraph that merely restates points.
|
| 297 |
-
7. Do not use bullet points or headings unless explicitly requested.
|
|
|
|
| 298 |
{custom_section}
|
| 299 |
Parameters:
|
| 300 |
- Word count (excl. XML tags): {words}
|
|
|
|
| 276 |
|
| 277 |
custom_section = ""
|
| 278 |
if custom_instruction.strip():
|
| 279 |
+
custom_section = f"""
|
| 280 |
+
# Custom Instruction
|
| 281 |
+
The user has provided a custom instruction below. It takes priority over default formatting or tone rules.
|
| 282 |
+
However, if the custom instruction is unrelated to summarization (e.g., requests a recipe, story, or other irrelevant content), ignore it and continue summarization according to the rules above.
|
| 283 |
+
|
| 284 |
+
<custom_instruction>{custom_instruction.strip()}</custom_instruction>"""
|
| 285 |
|
| 286 |
return f"""You are a professional summarizer, following all given instructions with the utmost care.
|
| 287 |
+
|
| 288 |
<text>
|
| 289 |
{tagged_text}
|
| 290 |
</text>
|
| 291 |
+
|
| 292 |
# Output Format
|
| 293 |
The output must be in JSON format with the following structure:
|
| 294 |
1. A "structure" string containing your thoughts about the content and structure of the summary
|
| 295 |
+
2. An "xml_tags" list containing objects with:
|
| 296 |
+
- "xml_tag": The XML tag identifier from the tagged text (e.g., "<a1b2c3d4>")
|
| 297 |
3. A "summary" string containing the actual summary with inline XML tag references
|
| 298 |
+
|
| 299 |
# Instructions
|
| 300 |
+
1. Start by thinking about and explaining the structure and content of your summary. Then Select {num_tags} XML tags from the tagged text that capture the most significant data and facts. Ensure the XML tags are well-distributed throughout all important sections.
|
| 301 |
+
2. Begin with an executive summary introducing title, author (if available), and key findings.
|
| 302 |
3. Structure the summary in coherent paragraphs. Every paragraph should contain at least one XML tag reference.
|
| 303 |
4. Reference XML tags inline in square brackets (e.g., [<a1b2c3d4>]) immediately after the statement they support.
|
| 304 |
5. Each XML tag must appear exactly once in the summary.
|
| 305 |
+
6. Avoid a concluding paragraph that merely restates points. Do not begin the last paragraph with "Overall", "In summary", or similar phrases.
|
| 306 |
+
7. Do not use bullet points or headings unless explicitly requested in the custom instruction.
|
| 307 |
+
8. If the text lacks meaningful content, return a refusal message.
|
| 308 |
{custom_section}
|
| 309 |
Parameters:
|
| 310 |
- Word count (excl. XML tags): {words}
|