Constraints & Requirements in Prompt Engineering: Control AI Responses
Constraints & Requirements
Constraints and requirements are instructions that define the boundaries, conditions, standards, or specific expectations an AI system should follow when completing a task.
They help transform a general request into a more controlled and predictable task by specifying what must be included, what must be avoided, and what limitations must be respected.
Requirements specify what the AI response should contain, while constraints define the boundaries within which the task must be completed.
Why Are Constraints Important?
Without constraints, an AI system may produce a response that is technically relevant but unsuitable for the actual purpose.
Without Constraints
Create a lesson on Python functions.
With Requirements and Constraints
Create a lesson on Python functions for Class XI.
Requirements:
- Include definition, syntax, parameters, and return values.
- Include three practical examples.
- Include five practice questions.
Constraints:
- Keep it suitable for beginners.
- Limit the lesson to 45 minutes.
- Avoid advanced concepts.
- Use simple language.
The second prompt defines both the expected content and the boundaries of the response.
Requirement vs Constraint
| Term | Meaning | Example |
|---|---|---|
| Requirement | Something the output should contain or accomplish. | Include three examples. |
| Constraint | A boundary or restriction on the task. | Keep the response under 500 words. |
| Requirement | Specifies a desired feature or outcome. | Include a comparison table. |
| Constraint | Limits available choices or behavior. | Use only Python standard libraries. |
Common Types of Constraints
Constraints can control many aspects of an AI task.
| Constraint Type | Example |
|---|---|
| Length | Keep the answer under 500 words. |
| Audience | Write for Class VIII students. |
| Language | Use simple English. |
| Technology | Use PHP 8 and MySQL. |
| Scope | Discuss only supervised learning. |
| Format | Return the answer as a table. |
| Quantity | Generate exactly 10 questions. |
| Time | Design the activity for 40 minutes. |
| Resources | Use only the information provided. |
| Content | Include definitions and examples. |
1. Length Constraints
Length constraints control the approximate size of the response.
Explain Generative AI for school teachers.
Keep the explanation under 400 words.
Use:
- A short definition
- Five key points
- Three practical examples
- A final takeaway
Length requirements are useful when content must fit into a presentation slide, worksheet, notice, article, or revision sheet.
2. Quantity Constraints
Specify the required number of items when the quantity matters.
Generate exactly 15 Python practice questions.
Requirements:
- 5 easy questions
- 5 intermediate questions
- 5 advanced questions
Include an answer key at the end.
3. Audience Constraints
Audience requirements help control vocabulary, depth, examples, and explanation style.
Explain machine learning for Class VIII students.
Requirements:
- Use everyday examples.
- Explain technical terms.
- Include one simple analogy.
Constraints:
- Do not assume prior knowledge.
- Avoid advanced mathematical terminology.
4. Scope Constraints
Scope constraints prevent the response from expanding into unrelated topics.
Explain Python lists.
Focus only on:
- Creating lists
- Indexing
- Slicing
- Updating elements
- Common list methods
Do not discuss tuples, sets, or dictionaries.
5. Technology Constraints
Technical projects often require the AI to work within a fixed technology stack.
Build the requested feature for an existing application.
Requirements:
- Use PHP 8.
- Use MySQL.
- Use PDO.
- Use prepared statements.
Constraints:
- Do not introduce a new framework.
- Do not change the existing database structure.
- Do not modify unrelated modules.
6. Format Constraints
Format constraints specify how information should be presented.
Compare ChatGPT, Gemini, and Claude.
Requirements:
- Compare writing, coding, research, and data analysis.
Constraints:
- Return only a table.
- Use exactly five columns.
- Keep each cell concise.
7. Time Constraints
Time constraints are particularly useful for teaching, training, workshops, meetings, and project planning.
Design a lesson on Python functions.
Requirements:
- Include explanation, demonstration, and practice.
Constraints:
- Total duration must be 40 minutes.
- Reserve 10 minutes for hands-on practice.
- Reserve 5 minutes for assessment.
8. Resource Constraints
Resource constraints define which materials, tools, or information should be used.
Create a classroom activity on cybersecurity.
Requirements:
- Include a practical activity.
- Include five assessment questions.
Constraints:
- Use only freely available software.
- Assume students have access to a web browser.
- Do not require paid tools.
9. Content Requirements
Content requirements specify information that must appear in the response.
Explain Python exception handling.
The response must include:
- Definition
- Purpose
- Syntax
- try block
- except block
- else block
- finally block
- Two practical examples
- Three common mistakes
10. Quality Requirements
Quality requirements describe characteristics that the response should have.
Create revision notes on SQL JOINs.
Requirements:
- Be technically accurate.
- Use clear terminology.
- Include practical SQL examples.
- Explain each JOIN briefly.
The examples should be internally consistent
and easy for beginners to understand.
Must Include vs Must Avoid
A strong prompt can explicitly identify both required and excluded content.
Create a beginner lesson on Python functions.
Must include:
- Definition
- Syntax
- Parameters
- Return values
- Three examples
Must avoid:
- Decorators
- Lambda functions
- Recursion
- Advanced functional programming concepts
Requirements Checklist
A checklist can make a complex prompt easier to construct.
| Question | Example |
|---|---|
| What must be included? | Include three practical examples. |
| What must be excluded? | Do not discuss advanced topics. |
| Who is the audience? | Class IX students. |
| How long? | Under 500 words. |
| How many? | Generate 10 questions. |
| What technology? | PHP 8 and MySQL. |
| What format? | Return a table. |
| What quality standard? | Use technically accurate examples. |
Constraints Should Be Measurable Where Possible
A measurable constraint is generally easier to interpret than a vague one.
| Vague | More Specific |
|---|---|
| Keep it short. | Keep it under 300 words. |
| Give several examples. | Give three examples. |
| Make it easy. | Write for Class VIII beginners. |
| Don't use too much jargon. | Define every technical term when first introduced. |
| Give enough questions. | Generate 10 questions. |
Hard vs Soft Constraints
Some requirements are essential, while others are preferences.
| Type | Meaning | Example |
|---|---|---|
| Hard Constraint | Must be followed for the result to be usable. | Return valid JSON. |
| Hard Constraint | Essential technical limitation. | Use PHP 8 only. |
| Soft Constraint | A preferred characteristic. | Prefer concise explanations. |
| Soft Constraint | A stylistic preference. | Use a professional tone. |
When constructing complex prompts, identify which requirements are mandatory and which are merely preferences.
Constraints for Educational Content
Create a worksheet on Python conditional statements
for Class IX.
Requirements:
- 10 questions
- 3 easy questions
- 4 intermediate questions
- 3 application-based questions
- Include an answer key
Constraints:
- Suitable for beginners.
- Use Python syntax only.
- Avoid nested conditions.
- Complete the worksheet within 30 minutes.
Constraints for Examination Questions
Create 20 Class XII Computer Science questions
on Python file handling.
Requirements:
- 10 MCQs
- 5 short-answer questions
- 5 programming questions
- Include answers.
Constraints:
- Follow the specified syllabus topics only.
- Avoid topics outside the syllabus.
- Use examination-oriented language.
- Do not repeat questions.
Constraints for Coding Tasks
Create a Python program to process student marks.
Requirements:
- Accept marks for five subjects.
- Calculate total and average.
- Display pass/fail status.
- Handle invalid input.
Constraints:
- Use Python standard libraries only.
- Use functions.
- Do not use external packages.
- Do not use global variables.
- Keep the program beginner-friendly.
Constraints for Existing Code
Constraints are especially important when asking AI to modify an existing application.
Modify the existing PHP/MySQL student module.
Requirements:
- Add student search.
- Add filtering by class.
- Use prepared statements.
- Display matching records.
Constraints:
- Use PHP 8 and PDO.
- Do not change the existing database schema.
- Do not remove existing functionality.
- Do not rewrite unrelated files.
- Preserve the existing authentication system.
Constraints for Data Analysis
Analyze the provided examination dataset.
Requirements:
- Calculate subject-wise averages.
- Identify the highest and lowest averages.
- Identify missing values.
- Identify unusual values.
- Summarize the major findings.
Constraints:
- Use only the supplied dataset.
- Do not invent missing values.
- Clearly identify assumptions.
- Do not infer student information that is
not present in the dataset.
Constraints for Research
Analyze the provided research material
about generative AI in education.
Requirements:
- Identify major findings.
- Identify benefits.
- Identify risks.
- Identify research gaps.
Constraints:
- Use only the provided material.
- Clearly distinguish evidence from interpretation.
- Do not invent citations.
- Identify claims that require verification.
Constraints for Business Communication
Prepare a project update for senior management.
Requirements:
- Summarize progress.
- Highlight achievements.
- Identify risks.
- List pending decisions.
- Recommend next actions.
Constraints:
- Maximum 500 words.
- Use professional language.
- Avoid unnecessary technical terminology.
- Focus only on information relevant to management.
Constraints for AI-Generated Content
Content creation often benefits from explicit requirements covering audience, tone, structure, length, and prohibited content.
Write an article explaining prompt engineering
for school teachers.
Requirements:
- Include practical classroom examples.
- Include five reusable prompts.
- Include a short FAQ.
- End with a summary.
Constraints:
- Use professional but accessible language.
- Avoid unnecessary technical jargon.
- Keep the article between 1,000 and 1,500 words.
- Do not make unsupported claims about AI capabilities.
Combining Requirements with Output Format
Requirements describe what should be included, while output format controls how that information should be organized.
Create revision notes on Python dictionaries.
Requirements:
- Definition
- Syntax
- Five important methods
- Three examples
- Five practice questions
Constraints:
- Class XI level
- Beginner-friendly
- Maximum 800 words
Output:
Use these sections:
1. Definition
2. Syntax
3. Methods
4. Examples
5. Practice Questions
6. Quick Revision Table
Combining Role, Context, Instructions, and Constraints
The prompting techniques covered so far can be combined into a complete structured prompt.
ROLE:
Act as an experienced Computer Science teacher.
CONTEXT:
The learners are Class XI students.
They understand Python variables, conditions,
loops, and lists.
TASK:
Create a lesson on Python functions.
INSTRUCTIONS:
1. Explain the concept.
2. Demonstrate the syntax.
3. Provide three practical examples.
4. Include five practice questions.
REQUIREMENTS:
- Include parameters and return values.
- Include common mistakes.
- Include a revision summary.
CONSTRAINTS:
- Total lesson duration: 45 minutes.
- Beginner-friendly language.
- Do not introduce decorators or recursion.
- Keep examples short.
OUTPUT:
Use headings, code blocks, and a final summary table.
Conflicting Constraints
Constraints must be internally consistent.
"Write a detailed 2,000-word explanation" and "Keep the entire response below 200 words" are conflicting requirements.
When requirements conflict, revise them before submitting the prompt. Clearly identify which requirements are essential.
Too Many Constraints
Constraints improve control, but excessive restrictions can make a prompt unnecessarily complicated.
| Useful Constraint | Potentially Unnecessary Constraint |
|---|---|
| Keep it under 500 words. | Every paragraph must contain exactly three sentences. |
| Use PHP 8. | Every variable must have exactly seven characters. |
| Generate 10 questions. | Every question must contain exactly 18 words. |
| Use a comparison table. | Every table cell must contain exactly two sentences. |
Use constraints that have a clear purpose.
Requirements Should Be Relevant
A requirement should contribute to the intended outcome.
Before adding a requirement, ask: "Will this requirement materially improve the usefulness of the result?"
Constraint Hierarchy
Complex prompts may contain different categories of constraints. A useful way to organize them is:
This is not a universal rule for every AI system, but it provides a practical structure for designing prompts.
Constraints in Reusable Prompt Templates
Constraints become especially valuable when creating reusable prompts. Instead of repeatedly explaining preferences, include them directly in the template.
Create revision notes on [TOPIC].
Audience:
Class XI Computer Science students.
Requirements:
- Definition
- Key concepts
- Syntax where applicable
- Two practical examples
- Common mistakes
- Five practice questions
Constraints:
- Beginner-friendly language
- Avoid unrelated topics
- Keep the response under 1,000 words
Output:
Use headings, code blocks where required,
and a final revision table.
The topic can be changed while the overall structure remains reusable.
Constraints and AI Reliability
Constraints can improve task alignment and consistency, but they do not guarantee factual correctness.
A prompt can require accurate information, but the user should still verify important facts, calculations, citations, code, and decisions.
A requirement such as "be accurate" is useful as an objective, but it should not be treated as proof that the generated information is actually correct.
Practical Activity 1 — Add Constraints
Improve the following prompt by adding useful requirements and constraints:
Create a lesson on Python loops.
Add constraints for:
- Class level
- Lesson duration
- Difficulty
- Number of examples
- Number of practice questions
- Topics to exclude
Practical Activity 2 — Examination Prompt
Create a prompt for generating a Class XII Computer Science question paper.
Include requirements for:
- Number of questions
- Question types
- Difficulty levels
- Syllabus scope
- Answer key
- Output format
- Topics to exclude
Practical Activity 3 — Coding Constraints
Create a prompt asking AI to write a Python student-result program.
Add at least five technical constraints, such as:
- Use functions
- Use standard libraries only
- Validate input
- Handle errors
- Avoid global variables
Practical Activity 4 — Data Analysis Constraints
Create a prompt for analyzing school examination data while explicitly preventing the AI from inventing missing information.
Include requirements for statistical analysis, missing-value handling, assumptions, and output format.
Practical Activity 5 — Reusable Prompt Template
Build a reusable prompt template for creating educational notes on any Computer Science topic.
Your template should contain:
- Role
- Context
- Task
- Requirements
- Constraints
- Output format
Interview Questions
Q1. What are requirements in prompt engineering?
Requirements specify what the AI response should contain or accomplish.
Q2. What are constraints?
Constraints define boundaries, restrictions, or conditions within which the AI should complete a task.
Q3. What is the difference between a requirement and a constraint?
A requirement specifies something that should be included or achieved, while a constraint limits how the task should be completed.
Q4. Give examples of constraints.
Examples include word limits, audience level, technology stack, scope restrictions, output format, quantity, time, and resource limitations.
Q5. Why should constraints be measurable where possible?
Measurable constraints reduce ambiguity and make the expected output easier to evaluate.
Q6. What are hard constraints?
Hard constraints are mandatory requirements or limitations that must be satisfied for the output to be usable.
Q7. What are soft constraints?
Soft constraints are preferences that guide the output but are generally less critical than mandatory requirements.
Q8. Can too many constraints be harmful?
Yes. Excessive or unnecessary constraints can make prompts complicated and may reduce flexibility without providing useful benefits.
Q9. Should constraints contradict each other?
No. Requirements should be reviewed for consistency before the prompt is submitted.
Q10. Do constraints guarantee accurate AI responses?
No. Constraints improve control and task alignment but do not guarantee factual or technical accuracy.
Examination MCQs
Q1. What is a requirement in a prompt?
- Something the output should contain or accomplish
- A computer hardware component
- A network protocol
- A database engine
Answer: A
Q2. What is a constraint?
- A boundary or restriction on a task
- A type of programming language
- A computer monitor
- A database record
Answer: A
Q3. Which is a length constraint?
- Include three examples.
- Keep the answer under 500 words.
- Explain Python.
- Use a table.
Answer: B
Q4. Which is a quantity constraint?
- Use simple language.
- Generate exactly 10 questions.
- Use Python.
- Explain the topic.
Answer: B
Q5. Which is a technology constraint?
- Use PHP 8 and MySQL.
- Write a paragraph.
- Use five examples.
- Explain the topic.
Answer: A
Q6. Which is a scope constraint?
- Discuss only supervised learning.
- Use five examples.
- Write a table.
- Use simple language.
Answer: A
Q7. Why should contradictory constraints be avoided?
- They create conflicting requirements.
- They increase storage.
- They improve network speed.
- They install software.
Answer: A
Q8. Which is an example of a hard constraint?
- Prefer a friendly tone.
- Return valid JSON.
- Use an interesting example.
- Prefer short sentences.
Answer: B
Q9. What is a potential problem with excessive constraints?
- The prompt can become unnecessarily complex.
- The computer automatically shuts down.
- The AI receives unlimited memory.
- The internet connection improves.
Answer: A
Q10. Do constraints guarantee factual accuracy?
- Yes
- No
- Only for coding
- Only for education
Answer: B
Key Terms
| Term | Meaning |
|---|---|
| Requirement | Something that the AI output should contain or accomplish. |
| Constraint | A boundary, restriction, or condition placed on a task. |
| Hard Constraint | A mandatory condition that must be satisfied. |
| Soft Constraint | A preference that guides the response. |
| Scope | The defined boundaries of the subject or task. |
| Task Alignment | How closely the response matches the requested objective and requirements. |
Self-Assessment Checklist
- ☐ Define requirements.
- ☐ Define constraints.
- ☐ Distinguish requirements from constraints.
- ☐ Use length constraints.
- ☐ Use quantity constraints.
- ☐ Use audience constraints.
- ☐ Use scope constraints.
- ☐ Use technology constraints.
- ☐ Use format constraints.
- ☐ Use time and resource constraints.
- ☐ Distinguish hard and soft constraints.
- ☐ Identify contradictory requirements.
- ☐ Avoid unnecessary restrictions.
- ☐ Create reusable constraint-based prompts.
- ☐ Combine role, context, instructions, requirements, and constraints.
Key Takeaway
Requirements tell AI what the response should contain, while constraints define the boundaries within which the task should be completed.
Effective constraints can control scope, length, quantity, audience, technology, resources, time, content, and format. Use constraints that are relevant and measurable where practical, while avoiding unnecessary or contradictory rules.