MediumParsingPython 3
Prompt Section Extractor
Parse explicit prompt boundary markers while detecting outside text, duplicates, and unterminated sections.
35m2 sample tests3 hidden tests
Parse named prompt sections from explicit boundary markers.
Requirements
- Define
extract_sections(text). - Sections start with a line like
<<<name>>>. - A section ends with a line exactly
<<<END>>>. - Return
{"sections": dict, "errors": list}. - Store section content without the boundary lines.
- Strip one trailing newline from section content.
- Duplicate section names should produce
duplicate:name. - Text outside sections that is not blank should produce
outside_text. - Unterminated sections should produce
unterminated:name.
Example
python
1text = "<<<system>>>\\nBe brief.\\n<<<END>>>\\n"
2assert extract_sections(text)["sections"] == {"system": "Be brief."}Constraints
- Use explicit state tracking.
- Preserve internal newlines inside sections.
- Keep errors deterministic.
Editor
Results
Run sample tests or submit all tests.