Inferensys

Prompt

Pagination and Filtering Parameter Documentation Prompt Template

A practical prompt playbook for using Pagination and Filtering Parameter Documentation Prompt Template in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Define the job-to-be-done, the required inputs, and the boundaries where this prompt adds value versus where it breaks down.

This prompt is built for API designers and technical writers who need to produce a single, authoritative reference for pagination, sorting, and filtering parameters across a multi-endpoint API surface. The core job-to-be-done is consistency enforcement: taking an OpenAPI specification or a set of endpoint definitions and generating a unified parameter reference that eliminates naming drift, documents cursor vs offset patterns, enumerates filter operators, and validates that every paginated endpoint follows the same contract. Use this prompt when you are standardizing a sprawling API, onboarding new endpoints into an existing pagination convention, or auditing documentation for gaps where some endpoints silently deviate from the team's agreed patterns.

The prompt requires structured input: an OpenAPI spec file, a collection of endpoint definitions, or a documented API contract. It works best when the input already contains the raw parameter definitions, and the model's job is to normalize, cross-reference, and flag inconsistencies. Do not use this prompt for designing the pagination mechanism itself, generating implementation code, or documenting non-REST transport protocols without significant adaptation. It is a documentation standardization tool, not a backend design assistant. For high-risk APIs where pagination bugs could cause data loss or billing errors, always pair the generated reference with a human review step that verifies cursor stability, default page sizes, and maximum limit enforcement against the actual implementation.

Before running this prompt, gather the complete API contract and identify the specific pagination convention your team has adopted—whether it is cursor-based, offset-based, page-based, or a hybrid. If your team has not yet agreed on a convention, resolve that design decision first; this prompt documents and validates an existing standard, it does not create one. After generating the reference, use the built-in consistency checks to flag endpoints that are missing pagination parameters, using inconsistent parameter names, or lacking documented filter operators. The output should feed directly into your API reference portal or developer docs, with a clear changelog noting any breaking changes to parameter names or default values.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works, where it fails, and what you must provide before using it in production.

01

Good Fit: Consistent API Surface

Use when: You have multiple paginated endpoints that should follow the same cursor, offset, or page-based convention. Guardrail: Run the prompt across all endpoints in a single batch to detect inconsistencies in parameter naming, default page sizes, or sort field enumeration.

02

Good Fit: Spec-First or Annotated Codebases

Use when: Pagination parameters are defined in an OpenAPI spec, protobuf definitions, or structured source annotations. Guardrail: Provide the spec or annotation source as [INPUT] rather than asking the model to infer conventions from unstructured prose.

03

Bad Fit: Undocumented Legacy APIs

Avoid when: The API has no formal pagination contract and the model must reverse-engineer behavior from raw HTTP response traces. Guardrail: Use a contract discovery prompt first to extract observed patterns, then feed the structured output into this documentation prompt.

04

Bad Fit: Single Endpoint Without Reuse

Avoid when: You are documenting only one endpoint with no need for cross-endpoint consistency. Guardrail: Use a simpler parameter table prompt. This template adds overhead for consistency checks that provide no value on a single endpoint.

05

Required Inputs

Risk: Incomplete or missing inputs produce hallucinated parameter names, wrong default values, or invented sort fields. Guardrail: Provide [ENDPOINT_LIST], [PAGINATION_STYLE] (cursor/offset/page), [AUTH_CONTEXT], and [SORTABLE_FIELDS] for every endpoint. Validate output against the live API before publishing.

06

Operational Risk: Drift After Deployment

Risk: Pagination behavior changes in a backend release but documentation is not regenerated, causing integrator confusion and support tickets. Guardrail: Schedule this prompt to run in CI on every API spec change. Pair with the API Contract Drift Detection prompt to flag undocumented parameter changes before they reach the portal.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A copy-ready prompt for generating consistent pagination, sorting, and filtering parameter documentation across all API endpoints.

This prompt template generates standardized parameter tables for pagination, sorting, and filtering from your API specification. It enforces consistency across endpoints by requiring explicit cursor vs. offset patterns, filter operator definitions, sort field enumeration, and default page sizes. The output is designed to be directly embedded into API reference pages, with field-level detail that helps integrators understand pagination mechanics without reading implementation code.

text
You are an API documentation engineer. Generate a complete pagination, sorting, and filtering parameter reference for the endpoint described below.

[API_SPECIFICATION]

Generate documentation that covers:

1. **Pagination Parameters**
   - Pagination method: cursor-based, offset-based, or page-based
   - Parameter names, types, required/optional status, default values, and maximum limits
   - For cursor-based: next_cursor/prev_cursor semantics, cursor encoding, and cursor expiration behavior
   - For offset-based: offset and limit parameters, maximum limit, and total count availability
   - Response metadata fields: next_cursor, has_more, total_count, or equivalent

2. **Sorting Parameters**
   - Parameter name and format (e.g., sort_by, sort_order, order_by)
   - Complete enumeration of sortable fields from the endpoint's response schema
   - Sort direction syntax: ascending/descending conventions (asc/desc, +/- prefix, or separate order parameter)
   - Default sort order when no parameter is provided
   - Multi-field sort support and precedence rules

3. **Filtering Parameters**
   - For each filterable field: parameter name, type, supported operators, and multi-value support
   - Operator syntax: equals, not_equals, greater_than, less_than, contains, starts_with, in, between, is_null
   - Date/time filter formats and timezone handling
   - Enum field filter values with complete value lists
   - Boolean field filter conventions
   - Nested or relationship-based filter syntax if applicable
   - Combining multiple filters: AND/OR semantics and precedence

4. **Consistency Validation**
   - Flag any pagination parameter names that differ from other endpoints in the same API
   - Flag any sort field names that don't match response schema property names
   - Flag any filter operators that deviate from the API-wide filter convention
   - Flag any missing default values or undocumented maximum limits

[OUTPUT_SCHEMA]
{
  "endpoint": "string (HTTP method and path)",
  "pagination": {
    "method": "cursor | offset | page",
    "parameters": [
      {
        "name": "string",
        "type": "string",
        "required": boolean,
        "default": "string or null",
        "max_value": "number or null",
        "description": "string"
      }
    ],
    "response_metadata_fields": [
      {
        "name": "string",
        "type": "string",
        "description": "string"
      }
    ],
    "notes": "string (cursor encoding, expiration, or edge cases)"
  },
  "sorting": {
    "parameter_name": "string",
    "sortable_fields": [
      {
        "field": "string (must match response schema)",
        "type": "string",
        "description": "string"
      }
    ],
    "direction_syntax": "string (e.g., 'asc/desc', '+/- prefix')",
    "default_sort": "string",
    "multi_field_sort_supported": boolean,
    "notes": "string"
  },
  "filtering": {
    "parameters": [
      {
        "name": "string",
        "type": "string",
        "operators": ["string (e.g., eq, neq, gt, lt, contains, in, between)"],
        "multi_value_supported": boolean,
        "description": "string",
        "enum_values": ["string or null"]
      }
    ],
    "combination_logic": "string (AND/OR semantics)",
    "notes": "string (date formats, timezone handling, special cases)"
  },
  "consistency_flags": [
    {
      "severity": "warning | error",
      "field": "string",
      "issue": "string",
      "recommendation": "string"
    }
  ]
}

[CONSTRAINTS]
- Every sortable field name must exactly match a property name in the endpoint's response schema.
- Every filterable field must reference an existing response schema property or queryable field.
- Pagination parameter names must match the convention used by other endpoints in the same API.
- Default values must be explicitly stated; do not assume defaults.
- Maximum limits must be documented; if no limit exists, state "unlimited" with a warning.
- Enum filter values must list every valid value from the specification.
- If the specification is incomplete for any required field, flag it in consistency_flags rather than guessing.

To adapt this prompt, replace [API_SPECIFICATION] with your OpenAPI spec fragment, endpoint definition, or implementation code. Adjust [OUTPUT_SCHEMA] if your documentation system expects a different JSON structure. The [CONSTRAINTS] section enforces consistency rules; modify these to match your API's specific pagination conventions, such as requiring page_token instead of cursor or enforcing RFC 3339 date formats. For APIs with custom filter DSLs, add operator syntax rules to the constraints. Always run the output through a schema validator before publishing to catch hallucinated field names or missing required properties.

IMPLEMENTATION TABLE

Prompt Variables

Every placeholder the prompt expects, why it matters, and how to validate it before execution. Use this table to ensure all required inputs are present, well-formed, and within expected bounds before the prompt is assembled.

PlaceholderPurposeExampleValidation Notes

[ENDPOINT_LIST]

Array of endpoint paths or operationIds to document pagination and filtering for

["GET /users", "GET /orders", "listTransactions"]

Must be a non-empty array. Each entry must match an actual endpoint in the API spec or codebase. Validate with spec-parser diff before prompt execution.

[API_SPEC_SOURCE]

Full OpenAPI spec, protobuf definition, or annotated source code containing parameter definitions

openapi: 3.0.3 paths: /users: get: parameters: ...

Must be valid JSON or YAML parseable by standard spec parsers. Reject if spec fails to parse. For code annotations, require language-specific AST extraction to confirm parameter presence.

[PAGINATION_STYLE]

Declared pagination convention: cursor-based, offset-based, page-based, or hybrid

"cursor"

Must be one of: cursor, offset, page, hybrid. If hybrid, require explicit description of which endpoints use which style. Validate against actual query parameter names in [API_SPEC_SOURCE].

[DEFAULT_PAGE_SIZE]

Default number of items returned per page when client omits limit

20

Must be a positive integer. Validate against actual default in implementation code or spec schema default field. Flag mismatch if spec default differs from documented default.

[MAX_PAGE_SIZE]

Hard upper bound on page size the API enforces

100

Must be a positive integer greater than or equal to [DEFAULT_PAGE_SIZE]. Validate against rate-limit config or middleware source. Null allowed if no hard limit exists.

[FILTER_OPERATORS]

Set of supported filter operators beyond equality: gt, gte, lt, lte, neq, in, like, between

["eq", "gt", "lt", "in"]

Must be an array of strings from a closed enum. Validate each operator appears in at least one endpoint's parameter schema. Flag operators documented but not implemented.

[SORT_FIELDS]

Enumeration of fields that support sorting across all paginated endpoints

["created_at", "updated_at", "name", "email"]

Must be an array of field name strings. Validate each field exists in the response schema of at least one endpoint in [ENDPOINT_LIST]. Flag sort fields that appear in docs but not in schema.

[CONSISTENCY_CHECK_FLAG]

Boolean controlling whether the prompt should validate parameter naming consistency across all paginated endpoints

Must be true or false. When true, the prompt output must include a consistency report section. Validate that the report actually flags naming inconsistencies like 'limit' vs 'page_size' across endpoints.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the pagination and filtering documentation prompt into a CI/CD pipeline or doc generation workflow with validation, retries, and human review gates.

This prompt is designed to run as a batch documentation generation step inside a CI/CD pipeline or a scheduled doc refresh job. The typical trigger is a change to the OpenAPI specification file, a source annotation update, or a manual invocation via a docs platform CLI. The harness should extract the relevant endpoint definitions, pagination parameters, and filter schemas from the spec or codebase, then feed them into the prompt as structured [INPUT] blocks. Do not run this prompt on every commit to unrelated code paths; scope the trigger to paths affecting API contracts, query parameter definitions, or schema files that define pagination and filtering models.

Pipeline wiring: The harness should parse the OpenAPI spec (or equivalent source) to isolate all paginated endpoints. For each endpoint, construct a prompt call with: [ENDPOINT_PATH], [PAGINATION_STRATEGY] (cursor, offset, page-based, or keyset), [PAGE_SIZE_DEFAULT], [MAX_PAGE_SIZE], [SORT_FIELDS] with allowed directions, [FILTER_PARAMETERS] with operators and types, and [RESPONSE_SCHEMA] for the paginated envelope. The model should return structured output conforming to [OUTPUT_SCHEMA]—a JSON object with parameter_table, pagination_behavior, filtering_rules, sort_options, and examples. Validate the output immediately: check that every parameter in the spec appears in the documentation, that default values match, that enum values for sort directions are correct, and that example requests use valid filter operators. If validation fails, retry once with the validation errors injected into [CONSTRAINTS]. If the retry also fails, flag the endpoint for human review and block the doc merge.

Model choice and cost: Use a model with strong schema-following capability (GPT-4o, Claude 3.5 Sonnet, or equivalent) for the initial generation pass. For subsequent consistency-check runs where only diffs are evaluated, a smaller model may suffice. Cache the prompt prefix containing the style guide and output schema instructions to reduce token costs across hundreds of endpoints. Logging and audit: Log every generation with the prompt version, spec commit SHA, model used, validation results, and any human review flags. Store outputs in a review branch of the docs repository, not directly in production. Require a human approval step for any endpoint where the generated documentation changes an existing pagination parameter description, removes a documented filter, or alters default values. This prevents documentation regressions from automated runs. Failure modes to monitor: The most common production failures are (1) the model inventing filter operators not present in the spec, (2) omitting newly added pagination parameters, (3) misdocumenting cursor formats for keyset pagination, and (4) generating example requests that use incompatible filter combinations. Your eval suite should include test cases for each of these failure modes, and your harness should block merges when any eval case fails.

IMPLEMENTATION TABLE

Expected Output Contract

The structure, fields, and validation rules for the generated pagination and filtering parameter documentation. Use this contract to validate the model's output before publishing.

Field or ElementType or FormatRequiredValidation Rule

endpoint_path

string (e.g., /v1/users)

Must match an actual route in the source spec or code. Regex check: ^/.*$

pagination_method

enum: cursor | offset | page

Must be one of the allowed values. If null, fail. Cross-reference with actual implementation.

pagination_parameters

array of parameter objects

Each object must include name, type, required, default, and description. Array must not be empty for paginated endpoints.

filter_parameters

array of parameter objects

Each object must include name, type, operators, and example. Operators must be from allowed set: eq, neq, gt, gte, lt, lte, in, like.

sort_parameters

array of sort field objects

Each object must include field_name and sort_direction enum. Field names must match actual response schema fields.

default_page_size

integer

Must be a positive integer. If not specified in source, default to 20. Validate range: 1-1000.

max_page_size

integer

Must be a positive integer greater than or equal to default_page_size. Validate range: 1-10000.

response_metadata_fields

array of string

Must include at minimum: next_cursor or total_count depending on pagination_method. Validate presence of documented fields in actual response schema.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when generating pagination and filtering parameter documentation, and how to guard against it.

01

Cursor vs Offset Confusion

What to watch: The prompt conflates cursor-based and offset-based pagination, producing documentation that mixes page parameters with next_cursor responses. This creates impossible integration paths for consumers. Guardrail: Explicitly constrain the prompt with a [PAGINATION_STRATEGY] variable set to cursor, offset, or page before generation. Validate output parameter names against the declared strategy.

02

Default Value Hallucination

What to watch: The model invents plausible but incorrect default values for page_size, limit, or max_results that don't match the actual API implementation. Consumers copy these into SDKs and hit unexpected limits or empty pages. Guardrail: Require a [DEFAULT_VALUES_SOURCE] input that maps each parameter to its actual default. Run a post-generation diff check between documented defaults and the source of truth.

03

Filter Operator Inconsistency

What to watch: The prompt documents gte for one endpoint and >= for another, or mixes contains with like across the same API surface. This inconsistency forces consumers to write endpoint-specific filter logic. Guardrail: Provide a [FILTER_OPERATOR_STANDARD] schema in the prompt that defines the canonical operator set. Add an eval step that checks every documented filter parameter against this standard.

04

Missing Sort Field Enumeration

What to watch: The prompt documents sort_by as accepting "any field" or lists only a subset of sortable fields, leaving consumers to guess which fields actually support sorting. Guardrail: Require a [SORTABLE_FIELDS] input array. Validate that every documented sort parameter references only fields from this list and explicitly states unsupported fields.

05

Response Envelope Mismatch

What to watch: The documented response shape shows items at the root, but the actual API wraps results in data.items or results. Consumers write deserialization code against the wrong envelope and get empty collections. Guardrail: Supply the exact [RESPONSE_ENVELOPE_SCHEMA] as a JSON Schema snippet. Run a structural comparison between the documented response and the actual API response shape.

06

Link Header vs Body Metadata Drift

What to watch: The prompt documents pagination links in response headers when the API actually returns them in the response body, or vice versa. Consumers look in the wrong place for next and loop infinitely or stop early. Guardrail: Include a [PAGINATION_LOCATION] constraint set to header, body, or both. Validate that the documented pagination metadata location matches the actual API behavior.

IMPLEMENTATION TABLE

Evaluation Rubric

Score the generated pagination and filtering parameter documentation before publishing. Each criterion targets a specific failure mode common in API reference generation.

CriterionPass StandardFailure SignalTest Method

Pagination Pattern Accuracy

Documented pattern (cursor, offset, page) matches the [OPENAPI_SPEC] or [SOURCE_CODE] exactly

Output describes offset pagination when the spec defines cursor-based pagination

Schema diff: extract pagination parameters from spec and compare to documented pattern

Parameter Completeness

All pagination and filtering parameters from the source contract are documented; no missing fields

A required filter parameter present in the spec is absent from the generated documentation

Field enumeration: parse all query parameters from [OPENAPI_SPEC] and check each appears in output

Default Value Correctness

Every documented default value matches the source specification or implementation code

Documented default page size is 20 but the API actually defaults to 50

Value extraction: compare each documented default against the spec's default keyword or source constant

Filter Operator Documentation

All supported filter operators (eq, neq, gt, lt, in, like) are listed per filterable field with examples

A field supports range queries but the documentation only shows equality filtering

Operator coverage: for each filterable field in [SOURCE_CODE], verify all allowed operators appear in output

Sort Field Enumeration

Every sortable field is listed with its sort direction support (asc, desc) and default sort order

Output lists created_at as sortable but omits updated_at which the API also supports

Enumeration check: extract sortable fields from [OPENAPI_SPEC] or [SOURCE_CODE] and diff against documented list

Cursor Semantics Documentation

Cursor lifecycle is documented: how to obtain the first cursor, when a cursor expires, and how to detect end-of-results

Output mentions cursors but does not explain that an empty next_cursor signals the last page

Semantic completeness: check for presence of cursor acquisition, expiration, and termination signals in output

Error Response Coverage

Pagination-specific error responses (invalid cursor, out-of-range page, unsupported filter) are documented with HTTP status codes and error body schemas

Output documents only 200 responses and omits 400 and 404 errors for invalid pagination parameters

Error trace: enumerate error responses from [SOURCE_CODE] or [OPENAPI_SPEC] and verify each appears with correct status code

Cross-Endpoint Consistency

Pagination and filtering conventions are consistent across all endpoints documented in the same batch

Endpoint A documents limit as the page size parameter but Endpoint B uses page_size without explanation

Consistency scan: extract pagination parameter names across all endpoints in [OPENAPI_SPEC] and flag mismatches

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single endpoint and lighter validation. Replace [API_SPEC_OR_CODE] with a small OpenAPI snippet or one annotated endpoint. Set [CONSISTENCY_CHECK_DEPTH] to basic and skip cross-endpoint comparison. Accept markdown table output without strict schema enforcement.

Watch for

  • Missing pagination style detection (cursor vs offset)
  • Undocumented default page sizes
  • Filter operators described vaguely rather than enumerated
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.