diff --git a/python/langsmith/client.py b/python/langsmith/client.py index 0bc09a4b8..6df0f9004 100644 --- a/python/langsmith/client.py +++ b/python/langsmith/client.py @@ -5328,7 +5328,7 @@ def list_prompt_commits( owner, prompt_name, _ = ls_utils.parse_prompt_identifier(prompt_identifier) params = { - "limit": limit if limit is not None else 100, + "limit": min(100, limit) if limit is not None else limit, "offset": offset, "include_model": include_model, } @@ -5347,12 +5347,12 @@ def list_prompt_commits( if not items: break for it in items: - i += 1 + if limit is not None and i >= limit: + return # Stop iteration if we've reached the limit yield ls_schemas.ListedPromptCommit( **{"owner": owner, "repo": prompt_name, **it} ) - if limit is not None and i >= limit: - break + i += 1 offset += len(items) if offset >= total: