The trick is to create and maintain (by aggregating perceptions) a structure in the brain which reflects reality as it is and pattern-match and validate against this inner structure.
The structure is to be continuously updated with new pieces which fits (have no contradiction with) the current structure, like in a jigsaw puzzle - only one piece fits.
Parts of the structure must be quickly discarded if found to be contradictory to the facts (empirically verified notions, traced back to The First Principles).
By the Nature of this Universe (which is one unfolding process) contradictions does not exist - only wrong premises.
Every animal does this, every brain, even AI does this.