Skip to content

fix(serving): bound validation error logging - #3056

Open
ananthsub wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/bound-validation-error-logging
Open

fix(serving): bound validation error logging#3056
ananthsub wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
ananthsub:ananthsub/bound-validation-error-logging

Conversation

@ananthsub

Copy link
Copy Markdown
Contributor

Summary

  • replace full-body pretty printing on shared 422 handling with a 4 KiB escaped prefix and exact original byte size
  • bound validation error summaries to 20 entries and omit Pydantic's potentially large or secret-bearing input values
  • preserve FastAPI's standard 422 status, body, and headers byte-for-byte
  • keep logging failure from masking the client response

Correctness and reliability

The request has already crossed FastAPI's validation boundary; this change only alters diagnostics. Empty, JSON, non-JSON, control-character, unavailable-body, and multi-megabyte inputs are covered. Logged prefixes are escaped so request-controlled newlines and nulls cannot inject raw control characters into logs.

Validation

  • uv run --extra dev pytest tests/unit_tests/test_server_utils.py -q — 33 passed
  • scoped pre-commit — passed

Focused benchmark

Median handler formatting time and traced peak allocation, comparing the previous two full json.dumps(..., indent=4) calls with the bounded logger:

  • 1 KiB: 0.039 ms / 0.004 MiB baseline; 0.044 ms / 0.007 MiB candidate
  • 2 MiB: 6.822 ms / 6.501 MiB baseline; 0.057 ms / 0.017 MiB candidate
  • 8 MiB: 30.243 ms / 26.001 MiB baseline; 0.071 ms / 0.016 MiB candidate

The tiny-body path is effectively unchanged; large-body CPU and allocation no longer scale with body size.

Closes #3007

Prevent malformed large requests from creating full-body formatting and logging amplification while preserving FastAPI's 422 response contract.

Signed-off-by: Ananth Subramaniam <ansubramania@nvidia.com>
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.

Cap request-body logging for validation failures

1 participant