1 validation error for ModerationInputsResult #12292

Closed
opened 2026-02-21 19:06:46 -05:00 by yindo · 3 comments
Owner

Originally created by @AlexiaChen on GitHub (Mar 28, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.0.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

docker logs -f <langgenius/dify-api:1.0.0>

logs:

2025-03-28 08:29:41.471 ERROR [Thread-81 (_generate_worker)] [app_generator.py:236] - Validation Error when generating
Traceback (most recent call last):
  File "/app/api/core/app/apps/chat/app_generator.py", line 223, in _generate_worker
    runner.run(
  File "/app/api/core/app/apps/chat/app_runner.py", line 93, in run
    _, inputs, query = self.moderation_for_inputs(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/app/apps/base_app_runner.py", line 358, in moderation_for_inputs
    return moderation_feature.check(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/moderation/input_moderation.py", line 49, in check
    moderation_result = moderation_factory.moderation_for_inputs(inputs, query)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/moderation/factory.py", line 38, in moderation_for_inputs
    return self.__extension_instance.moderation_for_inputs(inputs, query)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/moderation/api/api.py", line 55, in moderation_for_inputs
    return ModerationInputsResult(**result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/.venv/lib/python3.12/site-packages/pydantic/main.py", line 212, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ModerationInputsResult
action
  Field required [type=missing, input_value={'flagged': False}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.9/v/missing

✔️ Expected Behavior

No errors in logs

Actual Behavior

There errors show up

Originally created by @AlexiaChen on GitHub (Mar 28, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.0.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce docker logs -f <langgenius/dify-api:1.0.0> logs: ```txt 2025-03-28 08:29:41.471 ERROR [Thread-81 (_generate_worker)] [app_generator.py:236] - Validation Error when generating Traceback (most recent call last): File "/app/api/core/app/apps/chat/app_generator.py", line 223, in _generate_worker runner.run( File "/app/api/core/app/apps/chat/app_runner.py", line 93, in run _, inputs, query = self.moderation_for_inputs( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/app/apps/base_app_runner.py", line 358, in moderation_for_inputs return moderation_feature.check( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/moderation/input_moderation.py", line 49, in check moderation_result = moderation_factory.moderation_for_inputs(inputs, query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/moderation/factory.py", line 38, in moderation_for_inputs return self.__extension_instance.moderation_for_inputs(inputs, query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/moderation/api/api.py", line 55, in moderation_for_inputs return ModerationInputsResult(**result) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/pydantic/main.py", line 212, in __init__ validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pydantic_core._pydantic_core.ValidationError: 1 validation error for ModerationInputsResult action Field required [type=missing, input_value={'flagged': False}, input_type=dict] For further information visit https://errors.pydantic.dev/2.9/v/missing ``` ### ✔️ Expected Behavior No errors in logs ### ❌ Actual Behavior There errors show up
yindo added the 🐞 bug label 2026-02-21 19:06:46 -05:00
yindo closed this issue 2026-02-21 19:06:46 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 28, 2025):

The error you're encountering indicates that the ModerationInputsResult class is missing a required field, specifically the action field, during its initialization. The ModerationInputsResult class expects several fields, including flagged, action, preset_response, inputs, and query [1].

To resolve this issue, ensure that the result dictionary being passed to ModerationInputsResult(**result) includes all the required fields, particularly the action field. The action field should be an instance of ModerationAction, which specifies the action to be taken, such as DIRECT_OUTPUT or OVERRIDDEN [2].

Check the logic in your code where the result dictionary is constructed to ensure that it includes the action field with a valid value before passing it to ModerationInputsResult.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 28, 2025): <!-- Answer --> The error you're encountering indicates that the `ModerationInputsResult` class is missing a required field, specifically the `action` field, during its initialization. The `ModerationInputsResult` class expects several fields, including `flagged`, `action`, `preset_response`, `inputs`, and `query` <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/moderation/base.py)</sup>. To resolve this issue, ensure that the `result` dictionary being passed to `ModerationInputsResult(**result)` includes all the required fields, particularly the `action` field. The `action` field should be an instance of `ModerationAction`, which specifies the action to be taken, such as `DIRECT_OUTPUT` or `OVERRIDDEN` <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/moderation/factory.py)</sup>. Check the logic in your code where the `result` dictionary is constructed to ensure that it includes the `action` field with a valid value before passing it to `ModerationInputsResult`. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=other)</sup>
Author
Owner

@AlexiaChen commented on GitHub (Mar 28, 2025):

The error you're encountering indicates that the ModerationInputsResult class is missing a required field, specifically the action field, during its initialization. The ModerationInputsResult class expects several fields, including flagged, action, preset_response, inputs, and query [1].

To resolve this issue, ensure that the result dictionary being passed to ModerationInputsResult(**result) includes all the required fields, particularly the action field. The action field should be an instance of ModerationAction, which specifies the action to be taken, such as DIRECT_OUTPUT or OVERRIDDEN [2].

Check the logic in your code where the result dictionary is constructed to ensure that it includes the action field with a valid value before passing it to ModerationInputsResult.

To continue talking to Dosu, mention @dosu.

Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

I am a user of dify, not developer for Dify. I am so sorry that I cannot fix this type validation error now

@AlexiaChen commented on GitHub (Mar 28, 2025): > The error you're encountering indicates that the `ModerationInputsResult` class is missing a required field, specifically the `action` field, during its initialization. The `ModerationInputsResult` class expects several fields, including `flagged`, `action`, `preset_response`, `inputs`, and `query` [[1]](https://github.com/langgenius/dify/blob/main/api/core/moderation/base.py). > > To resolve this issue, ensure that the `result` dictionary being passed to `ModerationInputsResult(**result)` includes all the required fields, particularly the `action` field. The `action` field should be an instance of `ModerationAction`, which specifies the action to be taken, such as `DIRECT_OUTPUT` or `OVERRIDDEN` [[2]](https://github.com/langgenius/dify/blob/main/api/core/moderation/factory.py). > > Check the logic in your code where the `result` dictionary is constructed to ensure that it includes the `action` field with a valid value before passing it to `ModerationInputsResult`. > > _To continue talking to [Dosu](https://dosu.dev), mention [@dosu](https://github.com/dosu)._ > > Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c4c3cd6c-1243-4dfb-864a-e3256e30e6e0?feedback_type=other) I am a user of dify, not developer for Dify. I am so sorry that I cannot fix this type validation error now
Author
Owner

@AlexiaChen commented on GitHub (Mar 28, 2025):

sloved. the flag field is error when I using Content Moderation

@AlexiaChen commented on GitHub (Mar 28, 2025): sloved. the flag field is error when I using Content Moderation
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12292