Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rlm/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
from rlm.core.types import REPLResult, RLMIteration


def find_code_blocks(text: str) -> list[str]:
def find_code_blocks(text: str | None) -> list[str]:
"""
Find REPL code blocks in text wrapped in triple backticks and return List of content(s).
Returns None if no code blocks are found.
"""
if not text:
return []

pattern = r"```repl\s*\n(.*?)\n```"
results = []

Expand Down
10 changes: 10 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def test_no_code_blocks(self):
blocks = find_code_blocks(text)
assert blocks == []

def test_none_text_returns_empty_list(self):
"""LM clients can return None content (e.g. under tool-use pressure);
this must not raise a TypeError."""
blocks = find_code_blocks(None)
assert blocks == []

def test_empty_string_returns_empty_list(self):
blocks = find_code_blocks("")
assert blocks == []

def test_non_repl_code_blocks_ignored(self):
text = """Python block:
```python
Expand Down