Description
POST /api/v1/forms/fill accepts any string for input_text — including empty strings and whitespace-only input. An empty submission reaches Ollama and burns LLM cycles to return nothing useful for every field.
Steps to reproduce
- Send
POST /forms/fill with { "template_id": 1, "input_text": " " }
- Server processes the request fully — Ollama is called once per template field
- All fields return
-1 (not found), a useless filled PDF is written to disk
Fix
Add a @field_validator to FormFill in (api/schemas/forms.py):
from pydantic import BaseModel, field_validator
class FormFill(BaseModel):
template_id: int
input_text: str
@field_validator("input_text")
@classmethod
def validate_input_text(cls, v: str) -> str:
v = v.strip()
if not v:
raise ValueError("input_text cannot be empty or whitespace.")
if len(v) > 10_000:
raise ValueError("input_text exceeds maximum length of 10,000 characters.")
return v
No other files need changing — Pydantic will return a 422 automatically before the request reaches the controller.
Acceptance criteria
POST /forms/fill with empty or whitespace-only input_text returns 422
- Input exceeding 10,000 characters returns
422
- Valid input continues to work as before
Description
POST /api/v1/forms/fillaccepts any string forinput_text— including empty strings and whitespace-only input. An empty submission reaches Ollama and burns LLM cycles to return nothing useful for every field.Steps to reproduce
POST /forms/fillwith{ "template_id": 1, "input_text": " " }-1(not found), a useless filled PDF is written to diskFix
Add a
@field_validatortoFormFillin (api/schemas/forms.py):No other files need changing — Pydantic will return a
422automatically before the request reaches the controller.Acceptance criteria
POST /forms/fillwith empty or whitespace-onlyinput_textreturns422422