Skip to content

Add input validation and type conversion for user input #1476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 14, 2025

Conversation

Abbas-Asad
Copy link
Contributor

Summary

Fixed a type safety issue where user input was being used as a string without conversion to integer, which could cause runtime errors and type mismatches (in lifecycle_example.py).

Problem

The code was using input() which returns a string, but then using it directly in the f-string without converting it to an integer. This could cause:

  • Type mismatches when the string is passed to functions expecting integers
  • Runtime errors when users enter non-numeric input
  • Inconsistent behavior with the function signature expectations

Changes Made

Added proper input validation and type conversion:

  • Wrapped the input processing in a try-except block
  • Convert user input to integer using int(user_input)
  • Added error handling for invalid input with user-friendly message
  • Used the converted integer value in the f-string instead of raw string input

This ensures type safety and provides better user experience with proper error handling.

…_example.py)

## Summary

Fixed a type safety issue where user input was being used as a string without conversion to integer, which could cause runtime errors and type mismatches.

## Problem

The code was using `input()` which returns a string, but then using it directly in the f-string without converting it to an integer. This could cause:
- Type mismatches when the string is passed to functions expecting integers
- Runtime errors when users enter non-numeric input
- Inconsistent behavior with the function signature expectations

## Changes Made

Added proper input validation and type conversion:
- Wrapped the input processing in a try-except block
- Convert user input to integer using `int(user_input)`
- Added error handling for invalid input with user-friendly message
- Used the converted integer value in the f-string instead of raw string input

This ensures type safety and provides better user experience with proper error handling.
@seratch seratch added the documentation Improvements or additions to documentation label Aug 14, 2025
@seratch seratch merged commit 4b229d1 into openai:main Aug 14, 2025
6 checks passed
vcshih pushed a commit to veris-ai/openai-agents-python that referenced this pull request Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants