Provided are tricyclic pyrimidine and pyridine compounds of the general formulae (Ia) and (Ib), where the variables are as defined in the specification. Examples of the compounds include 2-(4-{ [4-(7H-pyrrolo[3,2-e][1,2,3]triazolo[1,5-c]pyrimidin-1-yl)piperidin-1-yl]methyl} phenoxy)acetonitrile, 1-{ trans-4-[(3-hydroxyazetidin-1-yl)methyl]cyclohexyl} -1H-pyrrolo[3&rsquo,2&rsquo:5,6] pyrido[4,3-d]pyrimidine-2,4-(3H,7H)-dione, and 1-(trans-4-(hydroxymethyl)cyclohexyl)-1H-pyrrolo[2,3-h][1,6]naphthyridin-4(7H)-one. The compounds are inhibitors of Janus kinase (JAK). The compounds may be useful in the treatment of autoimmune, inflammatory and allergic diseases.