From 4c4912839fc98b88a6961d5fe839673344d61a88 Mon Sep 17 00:00:00 2001 From: Caezarr <96132604+Caezarr@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:04:38 +0100 Subject: [PATCH] Show an error instead of a traceback for invalid llm schemas dsl input --- llm/cli.py | 5 ++++- tests/test_llm.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/llm/cli.py b/llm/cli.py index 30f824ab9..efe80831f 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -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)) diff --git a/tests/test_llm.py b/tests/test_llm.py index b6e141e24..f12046586 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -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(