In linguistics, grammaticality is determined by the conformity to language usage as derived by the grammar of a particular speech variety. The notion of grammaticality rose alongside the theory of generative grammar, the goal of which is to formulate rules that define well-formed, grammatical sentences. These rules of grammaticality also provide explanations of ill-formed, ungrammatical sentences.
In theoretical linguistics, a speaker's judgement on the well-formedness of a linguistic 'string'—called a grammaticality judgement—is based on whether the sentence is interpreted in accordance with the rules and constraints of the relevant grammar. If the rules and constraints of the particular lect are followed, then the sentence is judged to be grammatical. In contrast, an ungrammatical sentence is one that violates the rules of the given language variety.