Skip to content

Add input validation to prevent empty user messages in translation example #1089

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mshsheikh
Copy link
Contributor

Problem:
The script allows empty or whitespace-only input from the user, which results in unnecessary agent executions and invalid translations.

Changes:

  • Added input validation to check if the user input is empty or whitespace-only.
  • If invalid, raises ValueError with a clear message: "Input message cannot be empty."
  • Prevents downstream agent execution when input is invalid.
msg = input("Hi! Enter a message, and we'll translate it to Spanish.\n\n")
if not msg.strip():
    raise ValueError("Input message cannot be empty.")

Benefits:

  • Ensures only valid, non-empty input triggers agent workflows.
  • Improves user experience by failing early with a descriptive error.
  • Avoids unnecessary API calls or agent runs for invalid inputs.

…ample

Problem:
The script allows empty or whitespace-only input from the user, which results in unnecessary agent executions and invalid translations.

Changes:
- Added input validation to check if the user input is empty or whitespace-only.
- If invalid, raises `ValueError` with a clear message: `"Input message cannot be empty."`
- Prevents downstream agent execution when input is invalid.

```python
msg = input("Hi! Enter a message, and we'll translate it to Spanish.\n\n")
if not msg.strip():
    raise ValueError("Input message cannot be empty.")
```

Benefits:
- Ensures only valid, non-empty input triggers agent workflows.
- Improves user experience by failing early with a descriptive error.
- Avoids unnecessary API calls or agent runs for invalid inputs.
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.

1 participant