Use this prompt when an AI coding agent must understand how runtime behavior is gated before planning any change that touches application logic. The primary job-to-be-done is discovery: producing a structured, auditable inventory of every feature flag, toggle, and runtime gate found in the repository. This includes their source locations, default values, gating conditions, and the SDK or configuration mechanism used. The ideal user is a developer or platform engineer integrating an AI coding agent into a workflow where editing a file without knowing its flag context could silently break a dark launch, override an operational kill switch, or create a change that never reaches users in production.
Prompt
Feature Flag and Toggle Discovery Prompt

When to Use This Prompt
Understand when to run feature flag discovery before an agent modifies gated code, and when to skip it.
Run this prompt before the agent edits any file that might be behind a flag, before refactoring conditional logic that appears to be dead code, and before reconciling code-level flags with infrastructure-level configuration such as LaunchDarkly, Split, or internal feature flag services. The prompt assumes the agent has read access to the repository and can search across source files, configuration files, environment variable definitions, and any feature flag SDK usage patterns. It is a discovery step, not a modification step. The output should be treated as a snapshot that may need reconciliation against a runtime config dump from the actual flag service, since flags defined only in infrastructure config and never referenced in application code will not appear in the code-level inventory.
Do not use this prompt when the repository is known to have no feature flags, when the agent is operating in a sandbox without access to the full codebase, or when the task is a trivial documentation or formatting change that does not interact with runtime behavior. Do not use it as a substitute for runtime flag evaluation during testing. The prompt is also inappropriate for repositories where feature gates are entirely external and referenced only through opaque configuration keys with no in-code usage patterns to discover. In those cases, pair the agent with a direct API call to the feature flag service instead. After running this prompt, the next step is typically to validate the discovered flags against a runtime configuration dump, flag any code paths that appear gated but have no matching flag definition, and proceed with the planned change only after confirming the flag's operational state.
Use Case Fit
Where the Feature Flag and Toggle Discovery Prompt works, where it breaks, and what you must provide before running it.
Good Fit: Codebase-First Discovery
Use when: you need to inventory feature flags defined in application code, config files, and build-time constants. The prompt excels at finding if blocks, SDK calls, and environment-variable gating logic. Guardrail: always pair code-level discovery with a runtime config dump to catch flags defined only in infrastructure or a feature management SaaS.
Bad Fit: Runtime-Only Toggle Sources
Avoid when: flags are defined exclusively in a third-party service (LaunchDarkly, Split.io) with no code-level references, or when toggles are injected via a CDN edge worker. The prompt cannot query external APIs. Guardrail: run a separate API fetch against your feature flag provider and merge the results with the code-level inventory before declaring completeness.
Required Input: Repository Context and Runtime Snapshot
What you must provide: a repository checkout with application source, config files, and build scripts, plus a JSON dump of the current runtime flag state. Without the runtime snapshot, the prompt cannot distinguish active flags from dead code. Guardrail: validate that the runtime dump timestamp matches the repository commit being scanned to avoid drift.
Required Input: Flag SDK and Pattern Hints
What you must provide: the specific SDK, library, or helper function names your team uses for flag evaluation (e.g., unleash.isEnabled, ldclient.variation, custom featureFlag() wrapper). Without these hints, the prompt may miss flags behind indirection layers. Guardrail: include a list of known flag-evaluation function signatures and any custom decorators or middleware that gate behavior.
Operational Risk: Stale or Dead Flag Confusion
Risk: the prompt may report flags that are defined in code but have been archived in the flag management system, or flags that are always-on in production. This inflates the inventory with noise. Guardrail: cross-reference every discovered flag against the runtime config dump and flag any code-level flag absent from the runtime state as potentially dead or retired.
Operational Risk: Partial Rollout and Targeting Blindness
Risk: the prompt sees the code path but not the targeting rules (percentage rollout, user segments, prerequisites) that determine who sees what. This can mislead an agent into assuming a flag behaves uniformly. Guardrail: annotate each flag with its runtime targeting metadata from the feature management system and warn the agent when targeting rules are unavailable.
Copy-Ready Prompt Template
A reusable prompt template with square-bracket placeholders for discovering feature flags and toggles across a codebase.
This prompt instructs an AI coding agent to systematically search a repository for feature flags, toggles, and runtime gates. It is designed to be copied directly into your agent harness, with all dynamic values replaced before execution. The template forces the agent to produce a structured inventory rather than a narrative summary, making the output machine-readable for downstream validation against a runtime configuration dump.
textYou are a codebase analysis agent. Your task is to discover all feature flags, feature toggles, and runtime behavior gates in the repository at [REPOSITORY_PATH]. ## SEARCH STRATEGY 1. Identify the feature flag library or framework in use by examining [DEPENDENCY_FILES]. 2. Search for flag evaluation calls using patterns from [FLAG_EVALUATION_PATTERNS]. 3. Search for flag definitions, defaults, and configuration using patterns from [FLAG_DEFINITION_PATTERNS]. 4. Cross-reference flags found in code with any flag configuration files at [FLAG_CONFIG_PATHS]. 5. Flag any toggles defined only in infrastructure config (e.g., environment variables, Kubernetes ConfigMaps) that have no corresponding application-code definition. ## OUTPUT SCHEMA Return a JSON object with this exact structure: { "flags": [ { "flag_name": "string", "file_path": "string", "line_number": number, "default_value": "boolean | string | null", "conditions": ["string"], "evaluation_context": "string", "definition_source": "code | config | both", "infrastructure_only": boolean } ], "flag_library_detected": "string | null", "flags_found_only_in_infrastructure": ["string"], "search_coverage_notes": ["string"] } ## CONSTRAINTS - Do not include commented-out flag evaluations. - Do not include flags from [EXCLUDED_DIRECTORIES]. - If a flag's default value cannot be determined, set default_value to null. - For each flag, include the exact file path relative to the repository root. - If a flag appears in multiple files, list each occurrence as a separate entry. - Flag any flag whose name appears in infrastructure config but not in application code by setting infrastructure_only to true. ## EXAMPLES [FEW_SHOT_EXAMPLES] ## RISK LEVEL [RISK_LEVEL]
Adaptation guidance: Replace [REPOSITORY_PATH] with the absolute path the agent can access. Populate [DEPENDENCY_FILES] with a list like package.json, requirements.txt, go.mod, Cargo.toml so the agent knows where to look for the flag library. [FLAG_EVALUATION_PATTERNS] should include regex or AST patterns specific to the flag libraries your team uses—for example, if feature_flag('...') or unleash.isEnabled('...'). [FLAG_DEFINITION_PATTERNS] covers where defaults are set, such as flags.yml or const FLAGS = {...}. [FLAG_CONFIG_PATHS] points to directories like config/ or infra/ where runtime flag configuration lives. [EXCLUDED_DIRECTORIES] should list node_modules, vendor, .git, dist, build and any generated code directories. [FEW_SHOT_EXAMPLES] should contain 2–3 correctly formatted flag entries from your codebase to anchor the output format. Set [RISK_LEVEL] to high if flag misidentification could cause production incidents, triggering additional verification steps in the harness.
What to do next: After copying this template into your agent harness, run it against a repository where you already know the ground-truth flag inventory. Compare the agent's output against your manual inventory to measure recall and precision before trusting it on unfamiliar codebases. Pay special attention to flags_found_only_in_infrastructure—these are the flags most likely to be missed by code-only searches and most likely to cause surprises during deployment.
Prompt Variables
Required inputs for the Feature Flag and Toggle Discovery Prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to confirm the input is correct before execution.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[REPOSITORY_PATH] | Absolute path to the repository root the agent should scan for feature flags | /home/agent/repos/payment-service | Must be a readable directory. Check with os.path.isdir() before execution. Reject if path contains symlinks outside the workspace boundary. |
[FLAG_PROVIDER_HINTS] | List of known feature flag SDKs, libraries, or patterns used in this codebase | ["launchdarkly", "unleash", "custom_flags.yaml"] | Must be a non-empty array of strings. Validate each hint against known provider names. Null allowed if provider is unknown; agent will attempt heuristic discovery. |
[RUNTIME_CONFIG_PATH] | Path to a runtime configuration dump or environment variable file for cross-referencing flag states | /home/agent/runtime_dumps/production_config.json | File must exist and be valid JSON or dotenv format. Parse check before use. Null allowed if no runtime dump is available; harness must note that infrastructure-only flags may be missed. |
[SCAN_DEPTH] | Maximum directory depth for flag discovery to prevent unbounded traversal | 4 | Must be a positive integer between 1 and 10. Default to 4 if not specified. Reject values above 10 to prevent context-window exhaustion from excessive file listings. |
[EXCLUDE_PATTERNS] | Glob patterns for directories or files to skip during discovery | ["/node_modules/", "/vendor/", "**/.generated."] | Must be an array of valid glob strings. Test each pattern against a sample file tree before full scan. Default to common exclusion list if null. |
[OUTPUT_SCHEMA_VERSION] | Schema version for the output contract to ensure downstream parsers can validate the response | 1.0.0 | Must match semver pattern. Reject if format is invalid. Harness should compare against supported schema versions and abort if unsupported. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score for including a flag in the output inventory | 0.7 | Must be a float between 0.0 and 1.0. Flags below this threshold are placed in a separate low-confidence section. Default to 0.7 if not specified. |
Implementation Harness Notes
How to wire the Feature Flag and Toggle Discovery Prompt into an agent workflow with validation, runtime reconciliation, and safe fallbacks.
The Feature Flag and Toggle Discovery Prompt is not a standalone query—it is a structured extraction step that must be followed by validation against a runtime configuration dump. The prompt produces an inventory of flags with file locations, default values, and gating conditions, but it can only see what exists in application code. Flags defined exclusively in infrastructure-as-code, feature management SaaS dashboards, or environment-variable-only configs will be invisible to this prompt. The harness must therefore treat the prompt output as a partial inventory and reconcile it against an authoritative runtime source before any agent acts on flag state.
Wire the prompt into an agent workflow as a pre-edit discovery step. The agent should first run this prompt against the repository, then call a separate tool or API to fetch the current runtime flag configuration from the feature management system (LaunchDarkly, Flagsmith, custom config service, or environment-variable dump). The harness must merge these two sources: flags found in code but absent from runtime config are likely stale or dead; flags found in runtime config but absent from code are infrastructure-defined and require a different discovery path. Log discrepancies as warnings. For high-risk workflows—such as flag removal, default-value changes, or rollout percentage modifications—require human approval before the agent proceeds. The harness should also validate that every reported file location actually exists on disk and that extracted default values match the runtime defaults where both sources agree.
Model choice matters here. Use a model with strong code-structure reasoning and large context windows, since flag definitions can span multiple files and config layers. If the repository is large, pre-filter candidate files using ripgrep or AST-based search for common flag patterns (feature_flag, toggle, enabled, variant, experiment, LDClient, flagsmith, getValue, isEnabled) before passing them to the prompt. Set a retry policy: if the output fails schema validation—missing required fields like flag_name, file_location, or default_value—retry once with a stricter schema reminder. If the retry also fails, surface the partial output with validation errors and stop. Do not loop indefinitely. Store the final merged inventory as a structured artifact that downstream agent steps can reference, and version it alongside the commit SHA so future runs can detect drift.
Expected Output Contract
Fields, types, and validation rules for the feature flag inventory response. Use this contract to parse, validate, and integrate the model's output into downstream systems.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
flags | Array of objects | Must be a non-null array. If no flags are found, return an empty array, not null or a string. | |
flags[].name | String | Must match the exact flag key or constant name found in code. Non-empty. No inferred or guessed names allowed. | |
flags[].file_path | String (relative path) | Must be a valid relative path from repository root. File must exist in the provided file listing. Absolute paths or external references fail validation. | |
flags[].line_number | Integer | If provided, must be a positive integer. Null allowed when the flag is defined in infrastructure config rather than application code. | |
flags[].default_value | String or Boolean | Must be the literal default extracted from code or config. Use string representation for non-boolean values. Do not infer defaults from naming conventions. | |
flags[].conditions | Array of strings | Each condition must be a quoted expression found in the flag evaluation logic. Empty array allowed. Null not allowed; use empty array for no conditions. | |
flags[].source_type | Enum: 'code' | 'config' | 'infrastructure' | Must be one of the three enum values. 'infrastructure' flags require a note in the warnings field if no corresponding code reference was found. | |
warnings | Array of strings | Each warning must describe a specific concern: flag defined only in infrastructure config, stale flag with no recent references, or ambiguous naming. Empty array allowed. |
Common Failure Modes
Feature flag discovery prompts fail in predictable ways when the agent cannot distinguish code-level toggles from infrastructure config, misses dynamic evaluation, or confuses stale flags with active ones. These cards cover the most common production failure modes and how to prevent them.
Infrastructure-Only Flags Missed
What to watch: The agent scans application code but misses feature flags defined exclusively in launchdarkly, split.io, or cloud provider config stores with no code-level default. The inventory looks complete but is missing critical runtime toggles. Guardrail: Require a runtime config dump as a second input source. Cross-reference the code-derived flag list against the runtime flag list and flag any runtime-only toggles as high-priority findings.
Stale Flag False Positives
What to watch: The agent reports flags that were removed from code but still exist in config stores, or flags gating long-shipped features that are effectively always-on. The inventory inflates operational risk with dead toggles. Guardrail: Add a staleness check step that compares flag names against recent commit history. Flag any toggle with zero code references in the last 90 days as 'candidate for removal' rather than 'active feature gate.'
Dynamic Evaluation Blind Spots
What to watch: The agent finds the flag definition but misses that the flag value is determined at runtime by user attributes, percentage rollouts, or targeting rules rather than a static default. The inventory reports a single default value when the flag actually resolves to different values per context. Guardrail: Require the agent to classify each flag as 'static default,' 'context-dependent,' or 'percentage rollout.' Validate classification by sampling flag evaluation against multiple user contexts from the runtime config dump.
Flag Dependency Chains Ignored
What to watch: The agent treats each flag independently but misses that Flag A must be enabled for Flag B to take effect, or that Flag C overrides Flag D when both are active. The inventory is flat when the flag logic is hierarchical. Guardrail: Add a dependency detection pass that traces flag references within other flag conditions. Output a dependency graph alongside the flat inventory. Flag any circular dependencies or undocumented prerequisite chains.
Config Source Ambiguity
What to watch: The agent finds a flag name in code but cannot determine which config system owns it—environment variable, YAML file, remote config service, or database row. The inventory lacks source-of-truth attribution, making it useless for incident response. Guardrail: Require the agent to annotate each flag with its resolution precedence order. When multiple sources define the same flag, rank them by override priority and flag any conflicts between sources as 'needs reconciliation.'
Kill Switch vs. Feature Flag Confusion
What to watch: The agent lumps operational kill switches (circuit breakers, rate limiters, emergency off switches) together with product feature flags. The inventory mixes safety-critical controls with gradual rollout toggles, creating confusion during incidents. Guardrail: Add a classification dimension that separates 'operational control' from 'product feature.' Operational controls require different change management, monitoring, and rollback procedures. Flag any operational control that lacks an alert or runbook reference.
Evaluation Rubric
Test criteria for validating the feature flag discovery prompt output before integrating it into an agent harness. Each criterion targets a specific failure mode observed in production flag inventories.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Flag Completeness | Output contains all flags present in the provided [RUNTIME_CONFIG_DUMP] | Flag count in output is less than flag count in [RUNTIME_CONFIG_DUMP]; flags defined only in infrastructure config are missing | Parse both output and [RUNTIME_CONFIG_DUMP] into sets of flag keys; assert set equality |
Location Accuracy | Every flag entry includes a file path and line number that match the actual definition in the repository | File path points to a non-existent file; line number points to a line that does not define a flag; path is a symlink or generated file instead of the source definition | For each flag entry, open the reported file path and verify the line contains a flag definition matching the flag key |
Default Value Correctness | Default value for each flag matches the value in the source code definition, not the runtime override | Default value matches the runtime value instead of the code-level default; boolean flags reported as strings; null defaults reported incorrectly | Extract default values from source definitions and compare to output; flag any mismatch where the output default equals the runtime value but differs from the code default |
Condition Logic Extraction | All flag evaluation conditions are extracted and expressed in a readable form | Condition field is empty when the flag definition includes a non-trivial condition; complex conditions are truncated or paraphrased incorrectly; condition references an undefined targeting rule | For each flag with a non-empty condition in source, assert the output condition field is non-empty and contains the key operators from the source |
Flag Type Classification | Each flag is classified as boolean, string, number, or JSON with correct type | Boolean flag classified as string; JSON flag classified as string; type field is missing or null | Compare output type field against the actual type of the default value in source code; assert type field is one of the allowed enum values |
Infrastructure-Only Flag Detection | Flags found only in [RUNTIME_CONFIG_DUMP] and not in application code are flagged with source: 'infrastructure_only' | Infrastructure-only flags are omitted from output; infrastructure-only flags are reported with a fabricated file path; source field is 'code' for a flag with no code definition | Compute set difference between [RUNTIME_CONFIG_DUMP] flags and code-discovered flags; assert all difference flags appear in output with source 'infrastructure_only' |
Deprecation Status Identification | Flags marked as deprecated in code or config are identified with a deprecation note | Deprecated flag has no deprecation indicator; active flag is incorrectly marked as deprecated; deprecation note is present but empty | Search source code for deprecation annotations or comments near each flag definition; assert output deprecation field matches for flags with clear deprecation signals |
Output Schema Compliance | Output is valid JSON matching the [OUTPUT_SCHEMA] with all required fields present | Output fails JSON parse; required field is missing; field type does not match schema; extra fields not in schema are present | Validate output against [OUTPUT_SCHEMA] using a JSON schema validator; assert no validation errors |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Add a structured output schema, require a runtime config dump as a second input, and cross-reference application-code flags against runtime values. Include a confidence score per flag and a source field distinguishing code-defined from infra-defined flags.
codeAnalyze [CODEBASE_PATH] and [RUNTIME_CONFIG_DUMP] for feature flags. For each flag, produce: { "flag_name": string, "locations": [{file, line, expression}], "default_value": any, "runtime_value": any | null, "conditions": [string], "source": "code" | "infra" | "both", "confidence": 0.0-1.0, "stale_risk": "low" | "medium" | "high" } Flag stale_risk as "high" when runtime_value differs from all code defaults or when no code reference exists.
Watch for
- Runtime config dump format varies by platform (LaunchDarkly API response vs. env-var dump vs. Consul KV export); normalize before feeding to the prompt
- Flags gated by user segments or percentage rollouts may have no single runtime value
- Schema drift in production: add a post-processing validator that rejects outputs missing required fields

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us