[Bugfix]: only log extra fields for successfully deserialized objects #11367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR prevents unnecessary warning logging of detected extra fields present in the request for objects that are not validated by Pydantic.
In #10463 we allowed extra fields to be present in the request payload to comply with the OpenAI behavior. In order to still provide the users useful debug log if necessary, any extra field detected is warning-logged.
However, with the current implementation of the extra-field logging process, the extra fields detected are logged even if the pydantic validation process does not go through: this is a problem for objects that are tested against multiple
BaseModel
, as we log the detected extra fields, even though they are not relevant.For example, when calling the
/v1/embeddings
endpoint, the request payload will be validated for aEmbeddingRequest
object, which can be either aEmbeddingCompletionRequest
or aEmbeddingChatRequest
object.This leads to warning logs being generated even for valid embedding requests, since
input
which is a valid field for aEmbeddingCompletionRequest
is not a valid field for aEmbeddingChatRequest
(which expects themessages
field instead), which can mislead the user that something was wrong with their perfectly fine request.This PR changes the logic of logging those extra fields, by only logging the extra fields if the deserialization went through (object validated). This will only log the extra fields for validated objects:
Example with the following payload
{"model": "bge-multilingual-gemma2", "input": ["Hello world"], "another_field": "not_supported"}
BEFORE (detects extra fields both for the
EmbeddingCompletionRequest
andEmbeddingChatRequest
objects):AFTER (detects extra fields only for
EmbeddingCompletionRequest
which was validated):cc: @mgoin @DarkLight1337