Skip to content

fix: adding offset clamp#33

Open
usanvict wants to merge 1 commit into
apify:feat/modernize-langchain-integration-core-toolsfrom
usanvict:fix/offset-clamp
Open

fix: adding offset clamp#33
usanvict wants to merge 1 commit into
apify:feat/modernize-langchain-integration-core-toolsfrom
usanvict:fix/offset-clamp

Conversation

@usanvict
Copy link
Copy Markdown

Summary

  • Add _clamp_offset to _ApifyGenericTool that floors the offset parameter to 0, preventing invalid negative values from being sent to the Apify API
  • Apply the clamp in ApifyGetDatasetItemsTool._run where offset was previously passed through unchecked

Motivation

The limit parameter in ApifyGetDatasetItemsTool was already clamped via _clamp_items, but the offset parameter was passed directly to the API without validation. Per the Apify Get Dataset Items API, offset is a non-negative number (default 0) representing the number of items to skip. Negative values are invalid and could cause unexpected API behavior. It is especially necessary to minimise inappropriate token usage.

Changes

  • langchain_apify/tools.py — Added _clamp_offset static method to _ApifyGenericTool that ensures offset >= 0. Applied it in ApifyGetDatasetItemsTool._run.
  • tests/unit_tests/test_tools.py — Added test_clamp_offset_floor_is_zero covering three cases: negative offset is clamped to 0, zero passes through, and positive values pass through unchanged.

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.

2 participants