Skip to content

fix(python-sdk): validate ask() question and limit before signing (WALM-858) - #1255

Open
harrymove-ctrl wants to merge 2 commits into
devfrom
fix/issue-1249-python-ask-validation
Open

harrymove-ctrl wants to merge 2 commits into
devfrom
fix/issue-1249-python-ask-validation

Conversation

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator

Summary

ask() was the only text-taking method in the Python client that skipped _reject_blank_text. An empty question went to the LLM-backed /api/ask endpoint. Its limit was also sent as given: float("nan") was written as a bare NaN token (not valid JSON), and -1 and 2.5 were sent unchanged.

Changes

  • ask() rejects a blank question with ValueError("question cannot be empty").
  • New _require_positive_int helper: limit must be an int greater than 0, and bool is rejected. Otherwise it raises ValueError("limit must be a positive integer, got ..."). Both checks run before signing.

Tests

  • New tests/test_ask_validation.py: blank questions and limits of NaN, inf, -1, 0, 2.5, "5", True and None are rejected with nothing sent. A valid call goes out unchanged.
  • ruff check memwal/ tests/ and pytest tests/ -m "not integration" pass.

Estimate: 1 SP (incl. review)

Local results: ruff clean; pytest -m "not integration": 263 passed (new test failed 11/12 before the fix); mypy unchanged vs dev.

Linear: WALM-858

Fixes #1249

@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm when you have time, could you review this? Tracked in WALM-858, CI is green.

@ducnmm ducnmm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Include the Python release update with this SDK change.

The branch still carries Python 0.1.11, while current dev and main both carry 0.1.12 and that version is already on PyPI. This PR does not prepare a new release. After rebasing, keeping 0.1.12 makes release-python-sdk.yml skip stable publication, so users cannot receive this fix. Please prepare the next patch (currently 0.1.13), synchronize pyproject.toml, memwal/__init__.py, the package and docs changelogs, and the verifier pin. Re-evaluate the version if another unreleased patch lands first; use the manual release path.

Validation: 263 non-integration Python tests passed; Ruff clean. No new runtime regression found.

ask() was the only text-taking method without the blank-text check, so
an empty question reached the LLM-backed /api/ask endpoint, and its
limit was forwarded verbatim (NaN serialized as a bare, invalid-JSON
NaN token; negative and fractional values sent as-is). Reject a blank
question and any limit that is not a positive int.

Fixes #1249
The branch carried 0.1.11 and dev carries 0.1.12, which is already on PyPI, so release-python-sdk.yml would skip stable publication of this fix. Bump the Python SDK to 0.1.13 in pyproject.toml and memwal/__init__.py, add the 0.1.13 entry to the package and docs changelogs, and move the manual release verifier's Python pin to 0.1.13.
@harrymove-ctrl
harrymove-ctrl force-pushed the fix/issue-1249-python-ask-validation branch from 6d5162e to 213b96b Compare October 23, 2026 00:09
@harrymove-ctrl

Copy link
Copy Markdown
Collaborator Author

@ducnmm rebased on dev and prepared Python 0.1.13 (pyproject, __init__, both changelogs, verifier pin). Ruff is clean and tests pass.

This branch has not been deployed

No deployments
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.

Python ask() validates nothing: empty question is signed and sent, and limit accepts NaN (literal NaN token), -1, and 2.5

2 participants