
YAML 文件中使用三重双引号(""")定义长字符串会导致解析错误;正确方式是采用字面量块标量(|)保留换行,或使用折叠块标量(>)自动合并换行,避免非法嵌套引号和转义混乱。
yaml 文件中使用三重双引号(`"""`)定义长字符串会导致解析错误;正确方式是采用字面量块标量(`|`)保留换行,或使用折叠块标量(`>`)自动合并换行,避免非法嵌套引号和转义混乱。
YAML 对字符串格式有严格语法规则,尤其在处理多行、含换行符(\n)或特殊符号的长文本时,常见错误是误用 Python 风格的三重引号("""...""")。YAML 不支持类似 Python 的 triple-quoted 字符串拼接或隐式换行,直接写 """...""" 会被解析器视为语法冲突——因为 "" 已是一个空字符串值,后续紧接的 " 会被误判为非法标量起始。
✅ 正确做法:使用 字面量块标量(Literal Block Scalar),以 | 开头,保留原始换行与空白:
WORKFLOW:
EXTRACT_SUMMARIZATION:
PROMPT_SUMMARY: |
Extracting the timestamps of the goals scored by players in a football match using the commentator's description.
The structure of input is:
timestamp => text
timestamp => text
timestamp => text
timestamp => text
The output only consists of timestamps and does not include any text.
Example:
Input:
0:01 => [Applause]
0:04 => Welcome, ladies and gentlemen, to the match between Liverpool and Chelsea.
0:14 => Silva has scored, and the score is 1-0 in favor of Liverpool.
0:20 => So, there has been a foul committed by a Liverpool player.
0:25 => The referee has blown the whistle to end the first half.
0:30 => Chelsea has equalized through Ch.
0:45 => Tr has put Chelsea in the lead.
0:50 => So, the match has...
0:55 => ended, and the victory goes to Chelsea.
Output: 0:14, 0:30, 0:45
This is an incorrect format of output:
0:14 => Silva has scored, and the score is 1-0 in favor of Liverpool.
0:45 => Tr has put Chelsea in the lead.
This is another incorrect format of output:
0:01 => [Applause]
0:04 => 0:14 => 0:25 =>
Do it for the following text:
Input:
{}
Output:⚠️ 注意事项:
- | 后的换行会被保留为实际 \n(即 YAML 解析后字符串含真实换行),无需写 \n;
- 若需去除首尾空行,可加 |-(剪裁末尾换行)或 |+(保留末尾换行);
- 字面量块中 不解析转义序列(如 \n、\t 会原样保留为文字),因此不要在 | 块内写 \n;
- 如需自动将换行折叠为空格(适合段落文本),改用折叠块标量 >,例如 PROMPT: >;
- 避免使用在线 YAML 校验工具(如 yaml-validator),它们常基于过时解析器,反馈不可靠;推荐本地使用 ruamel.yaml 或 yamllint 进行验证;
- 文件扩展名应统一为 .yaml(官方推荐),而非 .yml(虽被广泛接受,但非标准)。
? 小技巧:若字符串中需包含 | 或 > 字符本身,只需确保其不出现在行首(缩进即可),YAML 会正常识别——字面量块标量天然支持引号、尖括号等任意字符,无需额外转义。

















