Skip to content

Commit b386eb6

Browse files
add runtime validation of syntax
this makes coverage drop dramatically
1 parent 131ab91 commit b386eb6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pydantic_ai_slim/pydantic_ai/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def __post_init__(self) -> None:
179179
re.compile(self.grammar)
180180
except re.error as e:
181181
raise ValueError('Regex is invalid') from e
182+
else:
183+
raise ValueError(f'Unsupported syntax {self.syntax}')
182184

183185

184186
class GenerateToolJsonSchema(GenerateJsonSchema):

tests/test_tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,11 @@ def test_function_text_format_lark_invalid():
14961496
FunctionTextFormat(syntax='lark', grammar='invalid grammar [')
14971497

14981498

1499+
def test_function_text_format_syntax_invalid():
1500+
with pytest.raises(ValueError, match='Unsupported syntax antlr'):
1501+
FunctionTextFormat(syntax='antlr', grammar="grammar T; a: 'a';")
1502+
1503+
14991504
def test_tool_definition_single_string_argument():
15001505
schema = {
15011506
'type': 'object',

0 commit comments

Comments
 (0)