Skip to content

Raise a clear error for schema DSL fields with no name#1469

Open
code-with-rashid wants to merge 1 commit into
simonw:mainfrom
code-with-rashid:schema-dsl-missing-name
Open

Raise a clear error for schema DSL fields with no name#1469
code-with-rashid wants to merge 1 commit into
simonw:mainfrom
code-with-rashid:schema-dsl-missing-name

Conversation

@code-with-rashid
Copy link
Copy Markdown

schema_dsl() crashes with an opaque IndexError when a field has no name before the colon (reachable from the CLI via llm schema dsl ':foo' and from resolve_schema_input):

>>> from llm.utils import schema_dsl
>>> schema_dsl(":just a description")
IndexError: list index out of range

After field.split(":", 1) the left-hand side is empty, so field_info.strip().split() returns [] and field_parts[0] is out of range.

This raises a ValueError naming the offending field instead, so the cause is obvious:

>>> schema_dsl(":just a description")
ValueError: Field is missing a name: ':just a description'

Valid schemas are unaffected.

Tests

Added test_schema_dsl_missing_field_name (parametrized over ':just a description' and 'name, :description') asserting the ValueError. pytest tests/test_utils.py passes (84 tests).

Closes #1466

schema_dsl() crashed with an opaque IndexError when a field had no name
before the colon (e.g. ":description" or "name, :description"), because
splitting the empty left-hand side yields no parts and field_parts[0]
is out of range. Raise a ValueError naming the offending field instead.

Closes simonw#1466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: schema_dsl() raises IndexError when a field has no name before the colon

1 participant