From 3467e0e5fe61583825851900e9a9cddf7f393343 Mon Sep 17 00:00:00 2001 From: Dunura Witharama Date: Wed, 21 Jan 2026 16:38:03 +0530 Subject: [PATCH] Validate input length in generate_id utility --- agentlightning/utils/id.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/agentlightning/utils/id.py b/agentlightning/utils/id.py index 7da109fd3..725f50c1e 100644 --- a/agentlightning/utils/id.py +++ b/agentlightning/utils/id.py @@ -7,12 +7,18 @@ def generate_id(length: int) -> str: - """Generate a random ID of the given length. + """Generate a random hexadecimal ID of the given length. Args: - length: The length of the ID to generate. + length: The desired length of the generated ID. Must be a positive integer. Returns: - A random ID of the given length. + A random hexadecimal ID string of the given length. + + Raises: + ValueError: If length is not a positive integer. """ + if length <= 0: + raise ValueError("length must be a positive integer") + return hashlib.sha1(uuid.uuid4().bytes).hexdigest()[:length]