liveBook · Manning

Constraint

As explained in Prompt Engineering in Practice

A constraint is a requirement that limits the inputs, behavior, or outputs permitted for a model interaction.

A constraint is a falsifiable condition that limits what a model’s response may contain or claim. In a structured prompt, instructions define the task; constraints bound acceptable results. Context supplies background, while output format prescribes the response’s shape. A constraint can restrict length, tone, content, or scope regardless of the task or format. section 2.3 section 2.0

Write constraints so someone can check the generated response:

  • Specify observable limits: “Use 120 to 160 words” or “Include exactly five bullet points,” rather than “write well.” section 2.3
  • Bound factual scope when needed: “Use only the provided information” or “Do not speculate.” section 2.3
  • Keep restrictions relevant, mutually consistent, and aligned with the instruction. Add only those needed for the task. section 2.3 section 2.8

Secure logging policy

Instruction: “Write secure logging guidelines for backend services.” Constraints: “Use 100 to 130 words. Include at least two explicit prohibitions using ‘Do not.’ Include ‘correlation ID’ at least once. Use a strict policy tone.” The instruction identifies the deliverable; the separate constraints make its length, wording, and tone checkable. section 2.3.1

Constraints also govern operational decisions. An incident-update prompt can require a neutral tone and prohibit speculation beyond supplied notes; a deployment brief can require concrete signals and, for a NO-GO recommendation, a rollback command. Put fixed headings and section order in the output-format specification so each requirement has a clear place. section 2.8.1 section 2.8.2

Test constraints against realistic inputs, especially requests that pull the model outside its assigned role. “Decline inappropriate requests” left a code-review assistant room to reinterpret its scope. A narrower prompt accepted only code for review and specified an exact fallback for other requests. Likewise, a policy assistant’s broad helpfulness instruction competed with a privacy restriction until the prompt explicitly excluded individual records and supplied a fallback. Constraints improve the likelihood of compliance; they do not enforce it. section 10.3.1 section 10.3.2 section 2.3

How Prompt Engineering in Practice covers it

How deep it goes
Defines falsifiability, gives measurable examples and selection guidance, and cautions that constraints cannot enforce compliance.
Examples
Uses secure logging guidelines, incident updates, deployment decisions, and restricted code-review and HR-policy assistants.
What it assumes
Introduces constraints alongside the other structural prompt elements rather than assuming their distinctions are known.
What you can do after
Apply it by writing checkable prompt restrictions and testing responses for violations or conflicts.
How it connects
Relates constraints to instructions, context, input parameters, output format, delimiters, and system prompts.

Also explained in

Compare how 19 books explain constraint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Prompt Engineering in Practice. The section links point to the parts of the book it draws on.