Skip to content

fix: add input validation and tests for /forms/fill endpoint#308

Open
Mahendrareddy2006 wants to merge 9 commits intofireform-core:mainfrom
Mahendrareddy2006:fix/form-validation
Open

fix: add input validation and tests for /forms/fill endpoint#308
Mahendrareddy2006 wants to merge 9 commits intofireform-core:mainfrom
Mahendrareddy2006:fix/form-validation

Conversation

@Mahendrareddy2006
Copy link

Summary

This PR enhances the /forms/fill endpoint by introducing proper input validation and improving overall request handling reliability. It ensures that invalid or malformed requests are rejected early, preventing unnecessary processing and potential downstream failures.


#Changes

  • Added validation to reject empty or whitespace-only 'input_text'

  • Added validation to ensure 'template_id' is valid (non-null and positive)

  • Introduced an optional upper limit on input length to prevent excessively large payloads

  • Improved error handling using consistent 'AppError' responses with appropriate status codes (400)

  • Removed redundant database calls by avoiding duplicate template fetching

  • Added unit tests covering:

    • valid request flow
    • empty input handling
    • invalid template ID
    • excessively long input

#Why

Previously, the endpoint accepted invalid inputs such as empty text or incorrect template IDs. This could lead to:

  • unnecessary LLM invocations (wasting compute/resources)
  • confusing error states or silent failures
  • inconsistent API behavior for clients

By validating inputs at the API boundary, we ensure that only meaningful and processable requests reach the business logic layer.


Result

  • API now returns clear and consistent 400 Bad Request responses for invalid inputs
  • Prevents unnecessary LLM processing and improves performance efficiency
  • Improves overall API robustness and predictability
  • Adds reliable test coverage to prevent regressions in the future

Notes

  • This change is backward-compatible for valid requests
  • Validation logic is lightweight and does not introduce performance overhead

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