The cognitive flexibility to select appropriate rules in a changing environment is essential for survival and is assumed to depend on the integrity of prefrontal cortex (PFC). To explore the contribution of the dorsolateral PFC to flexible rule-based behavior, we recorded the activity of cells in this region of monkeys performing a Wisconsin Card Sorting Test (WCST) analog. The monkey had to match a sample to one of three test items by either color or shape. Liquid reward and a discrete visual signal (error signal) were given as feedback to correct and incorrect target selections, respectively. The relevant rule and its frequent changes were not cued, and the monkeys could find it only by interpreting the feedback. In one-third of cells, cellular activity was modulated by the relevant rule, both throughout the trial and between trials. The magnitude of the modulation correlated with the number of errors that the monkeys committed after each rule change in the course of reestablishing high performance. Activity of other cells differed between correct and error trials independently from the rule-related modulation. This difference appeared during actual responses and before the monkeys faced the problems. Many PFC cells responded to the error-signal presentation, and, in some of them, the magnitude of response depended on the relevant rule. These results suggest that the dorsolateral PFC contributes to WCST performance by maintaining the relevant rule across trials, assessing behavioral outcomes, and monitoring the processes that could lead to success and failure in individual trials.