# How to wait until data in signal is valid

**URL:** https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628
**Category:** Community Support
**Tags:** python-sdk
**Created:** [March 20, 2023, 2:43pm UTC](https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628 "2023-03-20T14:43:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Isptn](https://avatars.discourse-cdn.com/v4/letter/i/e36b37/32.png) [@Isptn](https://community.temporal.io/u/Isptn)
#### Post date: [March 20, 2023, 2:43pm UTC](https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628/1 "2023-03-20T14:43:20Z")

</div>

I need to validate the data in activity before proceeding further, the question is how I can achieve that.  
By re-running workflow if data is not valid? Can I do it inside the signal definition? Or is there a better way?

```auto
    @workflow.run
    async def run(self, uuid: str) -> str:
        while True:
            await workflow.wait_condition(lambda: not (self._data is None), timeout=45)
            valid = await workflow.execute_activity(
                validate_data,
                self._data,
                start_to_close_timeout=timedelta(minutes=2)
            )
            if valid:
                #we are good
            else
                #signal that data is wrong, wait for new data

```

---

<div class="post-metadata">

### Author: ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)
#### Post date: [March 20, 2023, 2:46pm UTC](https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628/2 "2023-03-20T14:46:41Z")

</div>

Yes, you can do it in the signal definition or, as is often clearer, what you have there where you wait for the an attribute like `_data` to be set by a signal handler. It’s up to you on how to handle invalid data. If you want to fail the workflow, you can `raise temporalio.exceptions.ApplicationError("some error")`.

---

<div class="post-metadata">

### Author: ![Isptn](https://avatars.discourse-cdn.com/v4/letter/i/e36b37/32.png) [@Isptn](https://community.temporal.io/u/Isptn)
#### Post date: [March 20, 2023, 2:50pm UTC](https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628/3 "2023-03-20T14:50:08Z")

</div>

So I can do something like this:

```auto
    @workflow.signal(name="FORM_SUBMITED")
    async def form_submitted(self, res: str) -> None:
          valid = await workflow.execute_activity(
                validate_data,
                self._data,
                start_to_close_timeout=timedelta(minutes=2)
         )
         if valid:
            self._data = res
         else:
            # do something else

```

And it should work fine?

---

<div class="post-metadata">

### Author: ![Chad\_Retz](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/chad_retz/32/1396_2.png) [@Chad\_Retz](https://community.temporal.io/u/Chad_Retz)
#### Post date: [March 20, 2023, 3:02pm UTC](https://community.temporal.io/t/how-to-wait-until-data-in-signal-is-valid/7628/4 "2023-03-20T15:02:28Z")

</div>

Yes, however it can be confusing for readers if you put too much async logic inside of signal handlers. It separates the logic quite a bit so if, say, someone comes later and wants to add a `try`/`except` to catch all workflow errors and do something, they will miss errors that could occur here (errors out of signal handlers suspend/fail workflows just like if they were thrown out of run).

Often people will do something like you had before with `wait_condition` and set an attribute, or use an instance attribute of `asyncio.Queue` to push signals to and get them on the main `run` method. This keeps logic close together.
