Skip to content

Conversation

@Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Dec 3, 2025

This PR adds a helper to emit warnings on server request. This can be useful when a request completed successfully but we still want to warn the user about something. In practice we are checking the X-HF-Warning response header when hf_raise_for_status is called.

Expected format:

'X-HF-Warning: topic; message'

To avoid spamming the user, only 1 warning per topic is printed to the user. The topic itself is not printed, it is just a way to deduplicate them. Topic deduplication is case-insensitive. Topic is optional, in which case only the first non-labelled warning is printed.

A single HTTP request can contain several warnings by setting several times the X-HF-Warning (TIL headers are not unique^^).


Other alternatives explored:

  • Warning header: long-deprecated and not used in practice
  • Content-Warning draft: only a draft -so not yet a standard- + too much complexity for our use case. In this draft proposal, the warning message is set in the JSON body which is not as flexible as our approach. Warnings in body is theoretically more robust and powerful -with no size limit- but for our use case, using the header is fine (+ there is no body in HEAD calls + body is not always a JSON).

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! I left one comment about whether we should show all topic-less warnings or not

Copy link
Member

@julien-c julien-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use this PR to give a bit of context to the moon-landing team btw (in a moon-landing PR?) as i haven't yet shared a lot of context:)

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, nice and robust test

@Wauplin Wauplin merged commit 96fcc54 into main Dec 3, 2025
29 of 30 checks passed
@Wauplin Wauplin deleted the warn-on-server-warnings branch December 3, 2025 16:59
@Wauplin
Copy link
Contributor Author

Wauplin commented Dec 3, 2025

maybe use this PR to give a bit of context to the moon-landing team btw (in a moon-landing PR?) as i haven't yet shared a lot of context:)

I've created an issue -internal link- in moon with explanations (didn't want to start a PR just to give some details^^)

@severo
Copy link
Collaborator

severo commented Dec 4, 2025

A single HTTP request can contain several warnings by setting several times the X-HF-Warning (TIL headers are not unique^^).

thanks!

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.

7 participants