# How to validate any incoming observations against the observation space?

**URL:** <https://discuss.ray.io/t/how-to-validate-any-incoming-observations-against-the-observation-space/3310>\
**Category:** RLlib\
**Created:** [August 21, 2021, 11:25pm UTC](https://discuss.ray.io/t/how-to-validate-any-incoming-observations-against-the-observation-space/3310 "2021-08-21T23:25:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denys\_Ashikhin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/denys_ashikhin/32/58_2.png) [@Denys\_Ashikhin](https://discuss.ray.io/u/Denys_Ashikhin)\
**Post date:** [August 21, 2021, 11:25pm UTC](https://discuss.ray.io/t/how-to-validate-any-incoming-observations-against-the-observation-space/3310/1 "2021-08-21T23:25:32Z")

</div>

Hi,

Does anyone know if there is an easy way to validate any incoming observations against the observation space?

That is, if any values inside the current observations are outside the bounds of the defined observation space to raise an error or whatever?

---

<div class="post-metadata">

**Author:** ![sven1977](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sven1977/32/53_2.png) [@sven1977](https://discuss.ray.io/u/sven1977)\
**Post date:** [August 23, 2021, 7:08am UTC](https://discuss.ray.io/t/how-to-validate-any-incoming-observations-against-the-observation-space/3310/2 "2021-08-23T07:08:25Z")

</div>

RLlib already does this by default during training (however, it will only do it on a small sample of the data to avoid too much performance overhead of validation).  
Otherwise, you can - in your environment - do the check manually with `self.observation_space.contains(obs)`.

---

<div class="post-metadata">

**Author:** ![Denys\_Ashikhin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/denys_ashikhin/32/58_2.png) [@Denys\_Ashikhin](https://discuss.ray.io/u/Denys_Ashikhin)\
**Post date:** [August 28, 2021, 6:07pm UTC](https://discuss.ray.io/t/how-to-validate-any-incoming-observations-against-the-observation-space/3310/3 "2021-08-28T18:07:26Z")

</div>

Thanks a bunch, this function is actually a life saver!

I’m able to figure out the root cause of another (months long issue) that I can now close due to a dumb mistake. I’m hoping you can somehow merge these into one thread to unify it: [Randomly get empty queue when requesting action using PPO policy client + server · Issue #15753 · ray-project/ray · GitHub](https://github.com/ray-project/ray/issues/15753)
