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 llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2821,7 +2821,10 @@ def schemas_dsl_debug(input, multi):
\b
llm schema dsl 'name, age int, bio: their bio'
"""
schema = schema_dsl(input, multi)
try:
schema = schema_dsl(input, multi)
except ValueError as ex:
raise click.ClickException(str(ex))
click.echo(json.dumps(schema, indent=2))


Expand Down
14 changes: 14 additions & 0 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,20 @@ def test_schemas_dsl():
}


@pytest.mark.parametrize(
"dsl,expected",
(
("name, age badtype", "unknown type 'badtype' for field 'age'"),
(": no name", "field ': no name' is missing a name before ':'"),
("name, name", "duplicate field name 'name'"),
),
)
def test_schemas_dsl_invalid(dsl, expected):
result = CliRunner().invoke(cli, ["schemas", "dsl", dsl], catch_exceptions=False)
assert result.exit_code == 1
assert result.output == f"Error: Invalid schema DSL: {expected}\n"


@mock.patch.dict(os.environ, {"OPENAI_API_KEY": "X"})
@pytest.mark.parametrize("custom_database_path", (False, True))
def test_llm_prompt_continue_with_database(
Expand Down