mirror of
https://github.com/usestrix/strix.git
synced 2026-09-14 14:19:09 +08:00
187f41f36f
* Treat literal 'null'/'none' strings as absent for optional tool args Models routinely pass the literal string "null" or "none" instead of omitting an optional argument. Taken at face value it becomes a filter that matches nothing, so tools like list_notes / list_reports / list_requests silently return no results. Coerce such values to None in the central argument-coercion layer, but only for parameters the schema allows to be null (or that are absent from a declared "required" list), so required strings keep the literal value. The list/filter helpers normalize the same values too, so a direct call can't regress. * Limit nullish coercion to query tools and keep literal tags A literal "null"/"none" is only a mistake where the argument is a filter, so gate the coercion on read-only query tools; a tool that writes keeps the value, which stops update_note(content="none") from being read as "leave unchanged". Stop dropping nullish entries from a notes tag filter too: tags are free-form, so a literal "none" tag stays filterable and mixed tag queries keep every branch.
24 lines
832 B
Python
24 lines
832 B
Python
"""Nullish argument values passed by models in place of omitting an argument.
|
|
|
|
Models frequently send the literal string ``"null"`` / ``"none"`` for an
|
|
optional filter argument instead of leaving it out. Taken at face value it is
|
|
a filter that matches nothing, so the call quietly returns no results.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
NULLISH_STRINGS = frozenset({"null", "none", "nil", "undefined"})
|
|
|
|
|
|
def is_nullish(value: object) -> bool:
|
|
"""Whether ``value`` is a string standing in for "no value"."""
|
|
return isinstance(value, str) and value.strip().lower() in NULLISH_STRINGS
|
|
|
|
|
|
def clean_optional(value: str | None) -> str | None:
|
|
"""Normalize an optional filter argument: nullish or blank becomes ``None``."""
|
|
if value is None or is_nullish(value):
|
|
return None
|
|
return value.strip() or None
|