Chapter 10 Quiz: Specification-Driven Prompting

Test your understanding of specification-driven prompting concepts. Each question has one best answer unless otherwise noted.


Question 1

What is the primary advantage of specification-driven prompting over conversational prompting?

A) It is faster to write B) It eliminates ambiguity, leading to more predictable AI output C) It requires less domain knowledge D) It works with all AI models equally well

Answer **B) It eliminates ambiguity, leading to more predictable AI output** Specifications remove ambiguity by explicitly defining data types, constraints, edge cases, and expected behavior. This prevents AI from making incorrect assumptions, which is the primary source of errors in conversational prompting. Specifications take more time to write (not A), often require more domain knowledge (not C), and while they generally improve results across models, effectiveness varies (not D).

Question 2

Which of the following is a non-functional requirement?

A) "The system shall allow users to upload photos" B) "The system shall process uploads within 2 seconds" C) "The system shall support JPEG and PNG formats" D) "The system shall display a thumbnail after upload"

Answer **B) "The system shall process uploads within 2 seconds"** Non-functional requirements define quality attributes -- how well the system performs, rather than what it does. Performance (response time), security, reliability, and scalability are all non-functional requirements. Options A, C, and D all describe specific functionality the system must provide.

Question 3

In the MoSCoW prioritization method, what does the "S" in MoSCoW stand for?

A) Shall have B) Sometimes needed C) Should have D) Secondary requirements

Answer **C) Should have** MoSCoW stands for Must have, Should have, Could have, and Won't have. "Should have" features are important but not critical for the current release. They add significant value but the system can function without them.

Question 4

Which specification format is the industry standard for describing REST APIs?

A) GraphQL SDL B) JSON Schema C) OpenAPI (Swagger) D) Protocol Buffers

Answer **C) OpenAPI (Swagger)** The OpenAPI Specification (formerly known as Swagger) is the industry standard for describing REST APIs. GraphQL SDL is for GraphQL APIs, JSON Schema is for data validation, and Protocol Buffers is a serialization format primarily used with gRPC.

Question 5

What is the correct format for Gherkin-style acceptance criteria?

A) IF/THEN/ELSE B) GIVEN/WHEN/THEN C) INPUT/PROCESS/OUTPUT D) SETUP/ACTION/VERIFY

Answer **B) GIVEN/WHEN/THEN** Gherkin-style acceptance criteria use the GIVEN/WHEN/THEN format: GIVEN a context or precondition, WHEN an action occurs, THEN a specific result is expected. This format maps naturally to test cases and is widely used in Behavior-Driven Development (BDD).

Question 6

In test-first prompting, what is the correct workflow order?

A) Write code, write tests, refactor B) Write tests, have AI write code, run tests, refactor C) Have AI write tests and code simultaneously D) Write specification, write code, write tests

Answer **B) Write tests, have AI write code, run tests, refactor** Test-first prompting follows the TDD cycle adapted for AI: you write the tests (defining expected behavior precisely), have the AI generate implementation code to pass those tests, run the tests to verify correctness, and then refactor together. Writing tests first ensures they define the specification rather than just validating existing code.

Question 7

Which statement best distinguishes a specification from an implementation instruction?

A) Specifications use formal language; implementation instructions use informal language B) Specifications define what the system should do; implementation instructions define how to code it C) Specifications are longer; implementation instructions are shorter D) Specifications are written by architects; implementation instructions are written by developers

Answer **B) Specifications define what the system should do; implementation instructions define how to code it** The key distinction is what vs. how. "Passwords must be hashed with bcrypt" is a specification (what). "Create a function called hash_password that imports bcrypt and calls bcrypt.hashpw()" is an implementation instruction (how). Specifications give AI the freedom to choose the best implementation approach while constraining the required outcome.

Question 8

Which of the following is the BEST example of a formal specification element?

A) "Make the search fast" B) "Use good indexing on the database" C) "Search queries must return within 200ms for datasets up to 100,000 records" D) "Optimize the search function"

Answer **C) "Search queries must return within 200ms for datasets up to 100,000 records"** A formal specification element is measurable, specific, and unambiguous. Option C specifies an exact performance target (200ms) and the conditions under which it must be met (up to 100,000 records). Options A and D are vague, and option B is an implementation instruction rather than a specification.

Question 9

When using a SQL schema as a specification for AI code generation, what is the MOST important additional context to provide?

A) The specific SQL dialect documentation B) A description of the ORM framework to use and the operations needed C) The database server's hardware specifications D) Sample INSERT statements

Answer **B) A description of the ORM framework to use and the operations needed** While the SQL schema defines data structure, the AI needs to know what framework to use (e.g., SQLAlchemy, Django ORM) and what operations to generate (CRUD operations, specific queries, relationships). The schema alone tells the AI about the data but not about the code you want generated.

Question 10

In Design by Contract, what is a postcondition?

A) A condition that must be true before a method is called B) A condition that must be true after a method completes C) A condition that must always be true for the object D) A condition that defines when to raise an exception

Answer **B) A condition that must be true after a method completes** In Design by Contract: preconditions define what must be true before a method runs (A), postconditions define what must be true after a method completes (B), and invariants define what must always be true for the object (C). Postconditions are particularly useful for AI prompting because they define the expected outcome without specifying the implementation.

Question 11

What is the main risk of over-specifying when prompting AI?

A) The AI will ignore the specification entirely B) The specification may exceed the context window and be truncated C) Over-specification always produces better code D) The AI will generate code in the wrong programming language

Answer **B) The specification may exceed the context window and be truncated** When specifications are too long, they can exceed the AI's context window, causing important details to be lost or truncated. Additionally, over-specification wastes time on trivial components and can constrain the AI from choosing better implementation approaches. Option C is incorrect -- over-specification can hinder when requirements are changing or the task is simple.

Question 12

Which Python construct is MOST useful as an executable specification for data validation?

A) dataclass B) TypedDict C) Pydantic BaseModel D) NamedTuple

Answer **C) Pydantic BaseModel** Pydantic models serve as executable specifications because they combine type information, validation rules (min/max length, regex patterns, range constraints), and documentation in one place. They not only describe the data structure but enforce it at runtime. While dataclasses define structure and TypedDict defines types for dictionaries, neither provides the built-in validation capabilities of Pydantic.

Question 13

When should you prefer user stories over formal requirements documents for AI prompting?

A) When building safety-critical systems B) When the feature is user-facing and behavior-focused C) When working with complex algorithms D) When the system has no user interface

Answer **B) When the feature is user-facing and behavior-focused** User stories excel at capturing user-facing behavior because they frame requirements from the user's perspective. They naturally lead to acceptance criteria that define how the system should behave from the user's point of view. For safety-critical systems (A), formal requirements are more appropriate. For complex algorithms (C), test specifications may be better. For non-UI systems (D), API specs or requirements documents may be more suitable.

Question 14

What is the primary purpose of including error responses in an API specification?

A) To make the specification longer and more impressive B) To ensure AI generates proper error handling code for all failure cases C) To document what the API cannot do D) To satisfy OpenAPI format requirements

Answer **B) To ensure AI generates proper error handling code for all failure cases** Explicitly defining error responses in your API specification causes the AI to generate error handling code for each defined case. Without error response specifications, AI often generates only happy-path code or uses generic error handling. Specific error responses (400 for validation, 401 for auth, 409 for conflicts) lead to specific, appropriate error handling in the generated code.

Question 15

In the specification spectrum described in this chapter, which component typically warrants the HIGHEST level of specification formality?

A) Utility functions B) UI prototypes C) Database schemas D) Internal helper methods

Answer **C) Database schemas** Database schemas warrant high formality because data structures are foundational -- errors in the schema propagate to every component that interacts with the database. API endpoints are similarly high priority because they are contracts with consumers. UI prototypes and utility functions typically need less formal specification because they are either iterative (UI) or simple and well-understood (utilities).

Question 16

Which of the following is an example of a property-based test specification?

A) assert sort([3, 1, 2]) == [1, 2, 3] B) assert len(sort(input_list)) == len(input_list) for any input list C) assert sort([]) == [] D) assert sort([1]) == [1]

Answer **B) `assert len(sort(input_list)) == len(input_list)` for any input list** Property-based testing defines properties that must hold for all inputs, rather than specific input/output pairs. "The output length must equal the input length for any input" is a property. The other options are example-based tests that verify specific inputs produce specific outputs. Property-based tests are often used with libraries like Hypothesis that generate random inputs.

Question 17

What is the key benefit of using Python Protocol classes as interface specifications for AI?

A) They execute faster than abstract base classes B) They define component boundaries and method signatures that AI must implement C) They automatically generate test cases D) They are compatible with all programming languages

Answer **B) They define component boundaries and method signatures that AI must implement** Protocol classes define what methods a class must have, what parameters they take, and what they return. When given to AI, this creates a precise contract that the generated implementation must conform to. This promotes modular, maintainable code with clear component boundaries. Protocols do not generate tests automatically (C) and are Python-specific (not D).

Question 18

What is the recommended approach when your specification is too large for the AI's context window?

A) Reduce the specification to fit by removing details B) Split the specification into logical sections and implement one section at a time, providing shared context with each C) Use a model with a larger context window D) Convert the specification to a shorter format

Answer **B) Split the specification into logical sections and implement one section at a time, providing shared context with each** As discussed in Chapter 9 on context management, the most effective approach is decomposition: break the specification into logical sections (e.g., by domain area or component), implement each section separately, and include shared context (data models, common types, architectural decisions) with each section to maintain consistency. Simply removing details (A) loses important information.

Question 19

Which sign indicates you need MORE specification in your AI prompts?

A) The AI generates code quickly B) The AI keeps getting the same thing wrong after multiple iterations C) The code works on the first try D) The generated code uses appropriate design patterns

Answer **B) The AI keeps getting the same thing wrong after multiple iterations** When the AI repeatedly produces the same incorrect output despite conversational corrections, it usually indicates an ambiguity in your prompt that only a formal specification can resolve. The AI is interpreting your request consistently -- just not the way you intend. A specification eliminates the ambiguity and gives the AI the precise information it needs.

Question 20

What does the "incremental specification" approach recommend?

A) Writing the complete specification before any coding begins B) Starting with rough descriptions and progressively formalizing the most critical parts C) Generating specifications automatically from AI-generated code D) Writing specifications only after the project is complete

Answer **B) Starting with rough descriptions and progressively formalizing the most critical parts** Incremental specification is a pragmatic approach: start with rough descriptions to generate prototypes, identify the parts that matter most (data models, API contracts, critical business logic), write formal specifications for those parts, and keep other parts as conversational prompts until they stabilize. This balances the benefits of specifications with the overhead of writing them.

Question 21

When writing a configuration specification for AI, what is the MOST important thing to include?

A) Comments explaining each setting B) Environment-specific values and which values come from environment variables in production C) The configuration file format (YAML vs. JSON vs. TOML) D) The configuration management library to use

Answer **B) Environment-specific values and which values come from environment variables in production** The most important aspect of a configuration specification is distinguishing between hardcoded defaults and environment-specific values (especially secrets that must come from environment variables in production). This ensures AI generates code that properly handles configuration across development, testing, and production environments rather than hardcoding values that should be configurable.

Question 22

What is a key advantage of GraphQL SDL over OpenAPI for AI prompting?

A) It is more widely supported by AI models B) It naturally defines the type system and relationships in a compact, readable format C) It generates faster APIs D) It includes authentication specifications

Answer **B) It naturally defines the type system and relationships in a compact, readable format** GraphQL SDL provides a concise way to define types, relationships, queries, and mutations in a single readable document. While OpenAPI is more verbose (requiring separate request/response schemas), GraphQL SDL defines the entire type system compactly. Both are well-understood by AI models, but SDL's conciseness can be advantageous when context window space is limited.

Question 23

In the context of specification-driven prompting, what is an "executable specification"?

A) A specification written in a programming language B) A specification that can be run to verify whether code conforms to it C) A specification that generates code automatically D) A specification stored in a database

Answer **B) A specification that can be run to verify whether code conforms to it** An executable specification is one that can be executed as part of the development process to verify conformance. Test suites are the most common executable specification -- they define expected behavior and can be run to check if code meets that specification. Pydantic models are another example: they validate data against the specification at runtime.

Question 24

Which combination of specification types provides the MOST comprehensive coverage for a typical web API project?

A) User stories only B) Database schema + OpenAPI spec + test suite C) Requirements document + deployment spec D) Interface definitions + configuration spec

Answer **B) Database schema + OpenAPI spec + test suite** This combination covers the three critical layers: the database schema defines data structure and constraints, the OpenAPI spec defines the API contract (endpoints, request/response formats, errors), and the test suite provides executable verification of business logic and edge cases. Together, they address data, interface, and behavior -- the three dimensions most prone to AI generation errors.

Question 25

According to the chapter's "80/20 Rule of Specifications," where should you focus your specification effort?

A) On the simplest parts of the codebase to ensure they are correct B) On the 20% of code that contains 80% of the complexity C) On writing specifications for every function D) On the parts of the code that change most frequently

Answer **B) On the 20% of code that contains 80% of the complexity** The chapter advises focusing specification effort on the most complex parts of the system -- authentication, payment processing, complex business rules -- where ambiguity causes the most errors. Simple CRUD operations and utility functions rarely need detailed specifications. This targeted approach maximizes the return on the time invested in writing specifications.

Scoring Guide

  • 23-25 correct: Excellent -- you have a thorough understanding of specification-driven prompting
  • 19-22 correct: Good -- solid understanding with a few areas to review
  • 15-18 correct: Adequate -- review the sections related to questions you missed
  • Below 15: Review the chapter thoroughly before proceeding to Chapter 11