Inferensys

Prompt

Language and Framework Detection Prompt for Multi-Language Repos

A practical prompt playbook for using Language and Framework Detection Prompt for Multi-Language Repos 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 ideal user, required context, and when not to use this prompt.

This prompt is designed for AI coding agents that must orient themselves inside a polyglot repository—a codebase containing multiple programming languages, each potentially with its own build system, package manager, and framework conventions. The primary job-to-be-done is reliable language-to-directory mapping with framework version detection, so the agent can select the correct tooling, interpret project conventions, and avoid applying Python linting rules to a Go service directory. The ideal user is an AI engineer or platform developer building a coding agent harness that needs a structured, machine-readable repository overview before any file modification, test execution, or dependency analysis can safely proceed.

Use this prompt when an agent first enters an unfamiliar repository and must answer: which languages are present, where do they live, which frameworks are in use, and what versions are declared. The prompt expects access to a file listing or directory tree, the contents of standard config files (package.json, Cargo.toml, go.mod, requirements.txt, pyproject.toml, Gemfile, build.gradle, pom.xml, etc.), and optionally a README or build documentation. The output should be a structured mapping—typically JSON—that associates each detected language with its root directories, framework hints, and version constraints. This mapping becomes input to downstream prompts for build system identification, dependency graph traversal, and test runner discovery.

Do not use this prompt when the repository is known to be single-language, when the agent already has a reliable language map from a prior discovery step, or when the task is narrowly scoped to a single file where language detection can be inferred from the file extension alone. This prompt is also inappropriate for repositories where the primary challenge is not language detection but rather monorepo tooling coordination (e.g., Nx, Turborepo, Bazel), which requires a separate build system identification prompt. For repositories with embedded domain-specific languages (DSLs)—such as SQL inside Python, JSX inside JavaScript, or template languages inside server-side files—the harness must include post-processing logic to classify the host language as primary and the embedded DSL as a secondary notation, not a separate language entry. The next step after running this prompt is to feed the language map into a build system identification prompt and a dependency graph traversal prompt, ensuring the agent's understanding of the repository is layered and verifiable.

PRACTICAL GUARDRAILS

Use Case Fit

Where this prompt works and where it does not. Use these cards to decide if the Language and Framework Detection Prompt is the right tool for your polyglot repository before wiring it into an agent harness.

01

Good Fit: Polyglot Monorepos

Use when: your repository contains multiple languages across distinct directory trees (e.g., a Go backend in /services/, a TypeScript frontend in /web/, and Python scripts in /tools/). The prompt excels at producing a language-to-directory mapping with framework version hints extracted from config files. Guardrail: verify the mapping against ls and known build targets before trusting it for automated tool selection.

02

Bad Fit: Generated Code and DSLs

Avoid when: your repo contains large volumes of generated code in a different language than the source (e.g., Protobuf-generated Java from .proto files, or OpenAPI-generated clients). The prompt may misattribute the generated language as the primary language of a directory. Guardrail: pre-filter generated directories using .gitattributes linguist-generated markers or a static file listing before running detection.

03

Required Inputs: Config File Access

What to watch: the prompt relies on reading package.json, go.mod, Cargo.toml, requirements.txt, Gemfile, and similar config files to extract framework versions. If these files are absent, renamed, or in non-standard locations, version hints will be missing or hallucinated. Guardrail: provide a pre-scanned list of config file paths as [CONFIG_FILE_LIST] in the prompt template to reduce discovery failures.

04

Operational Risk: Embedded DSLs

Risk: a file may contain an embedded DSL within a primary language (e.g., GraphQL schemas in JavaScript template literals, SQL in Python strings, or JSX in TypeScript). The prompt may classify the file by its host language and miss the embedded DSL entirely. Guardrail: run a secondary pass with a dedicated DSL detection prompt for directories flagged as containing web frameworks, ORMs, or query builders.

05

Operational Risk: Monorepo Package Managers

Risk: monorepos often use different package managers per subdirectory (e.g., npm in one workspace, pnpm in another, and a root-level yarn). The prompt may report only the root package manager or conflate commands. Guardrail: pair this prompt with the Build System and Package Manager Identification Prompt and cross-reference outputs before executing any install or build commands.

06

Eval Criteria: Recall Against Ground Truth

What to watch: the prompt must detect all languages present above a minimum file-count threshold and must not invent languages not present in the repo. Guardrail: validate output against a ground-truth language inventory produced by a static analysis tool (e.g., GitHub Linguist or tokei). Flag any language in the prompt output that does not appear in the ground truth as a hallucination.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for detecting languages, frameworks, and version hints across a multi-language repository.

The prompt below is designed to be dropped into an agent harness that has already gathered a file listing, key config file contents, and directory structure from the target repository. It expects the agent to have read access to files like package.json, requirements.txt, go.mod, Cargo.toml, Gemfile, pom.xml, build.gradle, and CMakeLists.txt. The prompt instructs the model to produce a structured mapping of detected languages to directories, along with framework and version hints extracted from those config files. Use square-bracket placeholders to inject the specific file contents and directory listing your agent has collected.

text
You are analyzing a multi-language codebase to produce a language-to-directory mapping with framework and version hints.

## INPUT

### Directory Listing
[DIRECTORY_LISTING]

### Config File Contents
[CONFIG_FILE_CONTENTS]

## TASK

1. Identify every programming language present in the repository based on file extensions, config files, and build artifacts.
2. For each language, list the directories where that language is the primary or significant secondary language.
3. For each language, extract framework and version hints from the provided config files. Examples:
   - Node.js: Express version from package.json dependencies
   - Python: Django/Flask version from requirements.txt or pyproject.toml
   - Go: Module path and Go version from go.mod
   - Rust: Crate dependencies from Cargo.toml
   - Ruby: Rails version from Gemfile
   - Java: Spring Boot version from pom.xml or build.gradle
4. Flag any directories that contain generated code, vendored dependencies, or build outputs that should be excluded from language analysis.
5. Flag any files where the primary language is ambiguous (e.g., a `.js` file that is actually TypeScript with JSX, or embedded DSLs within a host language file).

## OUTPUT SCHEMA

Return a JSON object with this structure:
{
  "languages": [
    {
      "language": "string",
      "primary_directories": ["string"],
      "secondary_directories": ["string"],
      "frameworks": [
        {
          "name": "string",
          "version_hint": "string or null",
          "source_file": "string"
        }
      ],
      "build_tool": "string or null",
      "package_manager": "string or null",
      "confidence": "high|medium|low"
    }
  ],
  "excluded_directories": [
    {
      "path": "string",
      "reason": "generated|vendored|build_output|other"
    }
  ],
  "ambiguous_files": [
    {
      "path": "string",
      "detected_as": "string",
      "ambiguity": "string"
    }
  ]
}

## CONSTRAINTS

- Do not guess framework versions. If a version is not explicitly present in a config file, set version_hint to null.
- If a directory contains multiple languages, list it under the primary language and note it as a secondary directory for others.
- Treat `.git`, `node_modules`, `vendor`, `__pycache__`, `target`, `build`, `dist`, and similar directories as excluded by default.
- If you cannot determine a language with high confidence, mark it as low confidence and explain why in the ambiguity section.

To adapt this template, replace [DIRECTORY_LISTING] with the output of find . -type d or ls -R from the repository root, truncated to a reasonable depth. Replace [CONFIG_FILE_CONTENTS] with the concatenated contents of all discovered config files, each prefixed with its path. If your agent discovers config files iteratively, you can split this into two prompts: first detect config file paths, then feed only those files into this prompt. For very large repositories, consider chunking by top-level directory and merging results with a deduplication step.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Language and Framework Detection Prompt. Each variable must be populated before the prompt is assembled and sent. Validation notes describe how to programmatically verify the input quality before execution.

PlaceholderPurposeExampleValidation Notes

[REPO_ROOT_PATH]

Absolute path to the repository root on the agent's filesystem

/home/agent/workspace/project

Must be a readable directory. Validate with os.path.isdir() before prompt assembly. Fail if path does not exist or agent lacks read permission.

[FILE_LISTING]

Newline-separated list of all non-ignored file paths relative to repo root

src/main.py src/utils/helpers.js tests/test_main.py

Must contain at least 10 files for a meaningful scan. Validate count > 0. Strip binary and generated files using .gitignore rules. Warn if listing exceeds 5000 files and consider sampling.

[CONFIG_FILE_PATTERNS]

Glob patterns for config files that reveal language and framework versions

/package.json,/Cargo.toml,/pyproject.toml,/go.mod

Must be a comma-separated list of valid glob patterns. Validate that each pattern compiles without error. Default to a standard set if not provided. Warn if no patterns match any files in [FILE_LISTING].

[EXCLUDE_DIRS]

Directory names to skip during detection to avoid noise from vendored or generated code

node_modules,vendor,pycache,dist,build,.git

Must be a comma-separated list. Validate that excluded directories exist in the repo. Warn if a critical directory like src/ is accidentally excluded. Use case-insensitive matching for common patterns.

[MAX_FILES_TO_SCAN]

Upper bound on the number of files the agent should inspect for language detection

200

Must be a positive integer. Validate with isinstance(value, int) and value > 0. Default to 200 if unset. If [FILE_LISTING] count is below this threshold, scan all files. Warn if threshold is below 50 as detection accuracy may degrade.

[OUTPUT_SCHEMA]

Expected JSON schema for the language-to-directory mapping output

{"languages": [{"language": "string", "primary_directories": ["string"], "framework_hints": ["string"], "config_files_found": ["string"], "confidence": "float"}]}

Must be a valid JSON Schema object. Validate with a JSON Schema validator before prompt assembly. Reject if schema is missing required fields or contains circular references. Default schema provided if null.

[KNOWN_FALSE_POSITIVES]

File patterns or extensions that should not trigger language detection despite matching heuristics

.d.ts files in TypeScript repos are not a separate language; .h files in C++ repos are not C

.d.ts->TypeScript-declaration,.h->C++-header

Must be a comma-separated list of extension->explanation pairs. Validate format with regex. If empty, the prompt may misclassify generated declaration files or shared header extensions. Log a warning if no false-positive rules are provided for polyglot repos.

[EMBEDDED_DSL_PATTERNS]

Regex patterns to detect embedded domain-specific languages within primary language files

graphql... in JavaScript; SQL raw strings in Python: r'SELECT|sqlalchemy.text

graphql[^]*`,r'(SELECT|INSERT|UPDATE|DELETE)

Must be a comma-separated list of valid regex patterns. Validate each pattern compiles with re.compile(). If empty, the prompt may miss embedded GraphQL, SQL, or template languages. Test each pattern against a known positive sample file before prompt assembly.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the language and framework detection prompt into a reliable application workflow.

The language and framework detection prompt is designed to be called early in a repository exploration pipeline, before any code modification or deeper analysis tasks. It should be wired as a stateless, read-only step that takes a directory listing, a set of config file contents, and optionally a sample of source file extensions as input. The output is a structured mapping of directories to detected languages and frameworks with version hints. This mapping becomes a critical input for downstream agent decisions: which linter to run, which package manager to invoke, which test framework to use, and which coding conventions to apply. Because the prompt operates on file-level signals rather than executing code, it is safe to run in automated pipelines without sandboxing, but the harness must validate the output before any tool selection or code generation depends on it.

Integration pattern: The harness should collect the repository's top-level and second-level directory structure using find . -maxdepth 2 -type d or an equivalent tree walk, then extract the contents of known config files (package.json, Cargo.toml, go.mod, requirements.txt, pyproject.toml, Gemfile, build.gradle, pom.xml, Makefile, Dockerfile, .github/workflows/*.yml, etc.). These are passed into the prompt's [CONFIG_FILES] placeholder as a mapping of file paths to their raw contents. The [DIRECTORY_LISTING] placeholder receives the directory tree. Model choice: Use a fast, cost-effective model for this classification task (GPT-4o-mini, Claude Haiku, or equivalent) since it requires pattern matching on well-known file signatures rather than deep reasoning. Validation layer: After the model returns its JSON output, run a deterministic post-processor that checks: (1) every directory in the input listing appears in the output mapping or is explicitly classified as non-code (e.g., vendor/, node_modules/, .git/), (2) detected languages are in an allowed enum, (3) version strings match expected patterns (semver, date-based, or commit hashes), and (4) no directory is assigned conflicting primary languages without an explicit polyglot flag. Failed validations should trigger a retry with the validation errors appended to the prompt as [PREVIOUS_ERRORS].

Failure modes to instrument: The most common production failure is missed secondary languages in directories that contain embedded DSLs (e.g., SQL in Python files, JSX in JavaScript, template languages inside HTML). Log a warning when a directory contains files with extensions that don't match the detected primary language. A second failure mode is generated code misclassification—directories like dist/, build/, or generated/ may contain compiled or transpiled output in a different language than the source. The harness should exclude these directories from the input listing using a configurable ignore list. Retry logic: If validation fails, retry once with the error details injected into the prompt. If the second attempt also fails, fall back to a deterministic file-extension-based classifier and flag the directory for human review. Logging and observability: Record the input directory count, the number of languages detected, validation pass/fail status, retry count, and the model's latency. Attach the full prompt and response to the trace for debugging classification disagreements. Human review gate: For repositories with more than five detected languages or any detection confidence below a configurable threshold (default 0.7), route the output to a human reviewer before downstream agents consume it. This prevents a misclassified monorepo from cascading errors into build, test, or deployment steps.

Tool integration: This prompt is a pure classification step and does not require tool use, RAG, or external API calls. However, the harness should expose the validated output as a structured object that downstream agent tools can query: get_language_for_directory(path), get_framework_for_directory(path), get_package_manager_for_directory(path). These accessors prevent agents from re-running detection or making assumptions based on file extensions alone. Testing the harness: Before deploying, run the full pipeline against a curated set of 20-30 open-source repositories spanning monorepos, polyglot projects, single-language repos, and repos with generated code. Measure precision and recall against a manually labeled ground truth. Flag any repository where the pipeline disagrees with the ground truth for root-cause analysis. This eval suite should be re-run whenever the prompt template, model version, or validation rules change.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the language and framework detection output. Use this contract to parse the model response, validate correctness, and catch common failures before the result feeds downstream agent steps.

Field or ElementType or FormatRequiredValidation Rule

languages

Array of objects

Array length >= 1. Each object must have name and directories fields. Reject if empty or missing.

languages[].name

String (lowercase, trimmed)

Must match a known language identifier from a configurable allowlist. Reject unknown or hallucinated language names.

languages[].directories

Array of strings

Each path must be a relative directory path starting with ./ or a root-relative path. Validate that at least one path exists in the repository file listing. Reject if empty.

languages[].primary_framework

String or null

If present, must match a known framework name for the detected language. Null allowed when no framework is detected. Reject if framework is incompatible with language.

languages[].framework_version_hint

String or null

If present, must follow semver-like pattern or be a valid version string extracted from a config file. Null allowed. Reject if version format is unparseable.

languages[].config_files

Array of strings

Each entry must be a relative file path that exists in the repository. At least one config file per language entry. Reject if all paths are missing from the file listing.

languages[].confidence

Number (0.0 to 1.0)

Must be a float between 0.0 and 1.0 inclusive. Values below 0.5 should trigger a human review flag. Reject if outside range or not a number.

warnings

Array of strings

If present, each string must describe a specific detection ambiguity such as generated code in a different language or embedded DSL. Reject if warnings are generic or unactionable.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when detecting languages and frameworks in polyglot repos, and how to guard against it.

01

Generated Code Masks True Language

What to watch: The prompt misclassifies a directory because it's dominated by generated code (e.g., protobuf stubs, OpenAPI clients, or compiled assets) in a different language than the hand-written source. Guardrail: Add a pre-filter step that excludes well-known generated-code directories (gen/, dist/, target/, __pycache__/) before running detection. Validate by comparing against .gitattributes linguist-vendored markers or .gitignore patterns.

02

Embedded DSLs Confuse Primary Language

What to watch: Files with a primary language extension (e.g., .tsx) containing large blocks of an embedded DSL (GraphQL, SQL, JSX) get double-counted or misclassified. The prompt may report GraphQL as a top-level language when it only appears inside template literals. Guardrail: Instruct the prompt to distinguish between file-level language (by extension) and embedded DSLs (by content pattern). Require the output to separate primary languages from embedded DSLs with a confidence flag. Validate against a manual audit of 5-10 files flagged as ambiguous.

03

Framework Version Ambiguity from Sparse Configs

What to watch: The prompt extracts a framework name but guesses the version from a lockfile or a single config entry that may be stale, overridden, or pinned by a parent monorepo. Guardrail: Require the prompt to cite the exact config file and line that produced each version hint. If multiple configs conflict, surface the conflict rather than silently picking one. Add a post-processing check that cross-references package.json resolutions, Gemfile.lock, or requirements.txt pins before accepting a version.

04

Monorepo Package Manager Mismatch

What to watch: A monorepo uses different package managers per workspace (e.g., Yarn for frontend, Poetry for Python, Cargo for Rust). The prompt detects only the root-level package manager and misses per-directory tooling, causing downstream build or install failures. Guardrail: Instruct the prompt to scan each top-level directory independently for its own lockfile and config, not just the repo root. Validate by running find . -name '*.lock' -o -name 'pyproject.toml' and comparing the list against the prompt's output.

05

Vendor and Third-Party Code Inflation

What to watch: Vendored dependencies (e.g., vendor/, third_party/, libs/) contain large amounts of code in languages not used by the project itself. The prompt reports these as project languages, inflating the language count and misleading downstream tool selection. Guardrail: Exclude directories marked as vendored in .gitattributes, .gitmodules, or common vendor patterns. Add a post-processing rule that flags any language whose file count is >80% concentrated in a single vendor directory.

06

Config File Absence Causes Silent Framework Miss

What to watch: A framework is in use but its config file is non-standard, absent (relying on defaults), or embedded inside another file (e.g., FastAPI settings inside a Python module). The prompt reports no framework detected, leading the agent to use wrong assumptions. Guardrail: Add a secondary detection pass that inspects import statements and dependency lists for known framework packages even when config files are missing. Flag directories where imports suggest a framework but no config was found, and escalate for human confirmation.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for evaluating the Language and Framework Detection Prompt output before integrating it into a coding agent's repository exploration harness.

CriterionPass StandardFailure SignalTest Method

Primary language detection accuracy

Top-level language matches ground truth for all first-class source directories

A primary language is missed or a generated/vendor directory is misclassified as a primary language

Compare output against a manually verified language-to-directory mapping for a known polyglot repo

Framework version extraction from config files

Framework name and version string are correctly extracted from standard config files (e.g., package.json, Cargo.toml, go.mod)

Version is null when a valid config file exists, or version string includes non-version text (e.g., '^' or '>=')

Assert that extracted version matches the exact string in the config file for a set of known test repos

Directory scope exclusion

Generated code directories (e.g., dist/, build/, pycache/), vendor directories, and .git are excluded from the mapping

A directory containing only generated or vendored code appears in the output with a language label

Run the prompt on a repo with known generated code directories and assert those paths are absent from the output

Embedded DSL handling

Embedded DSLs (e.g., SQL in Python, GraphQL in TypeScript) are noted as secondary languages with the host file path, not misclassified as a primary directory language

An embedded DSL is reported as the primary language for its host directory, or the host file is omitted

Provide a file containing a known embedded DSL and verify the output lists it as a secondary language with the correct host file reference

Monorepo multi-language separation

Each package or service directory in a monorepo is independently classified with its own language and framework

A monorepo with Node.js and Python services is classified as a single language, or framework versions are conflated across packages

Use a monorepo fixture with two distinct service directories; assert each gets a separate entry with the correct language and framework version

Confidence scoring for ambiguous files

Files with ambiguous or no clear language (e.g., shell scripts, Makefiles) receive a confidence score below 0.8 and a note explaining the ambiguity

Ambiguous files receive a confidence score of 1.0 or are silently assigned a language without a caveat

Check output for known ambiguous file types; assert confidence < 0.8 and the notes field is non-empty

Output schema compliance

Output is valid JSON matching the expected schema with all required fields present and no extra top-level keys

Output is missing a required field (e.g., language, directories, framework), contains markdown wrapping, or includes hallucinated fields

Validate output with a JSON Schema validator; reject any response that fails schema validation or contains non-JSON text

Empty repository handling

Prompt returns an empty language list and a clear message indicating no source files were found, without hallucinating languages

Prompt hallucinates a language or framework for an empty repository, or returns a non-empty list with fabricated file paths

Run the prompt against an empty directory; assert the output language list is empty and a descriptive note is present

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a single model call and relaxed output validation. Accept the raw JSON or markdown table without schema enforcement. Focus on getting a directional language-to-directory map quickly.

Prompt modification:

  • Remove strict [OUTPUT_SCHEMA] constraints; ask for a markdown table instead.
  • Replace [CONFIDENCE_THRESHOLD] with a simple instruction: "List languages you are confident about; skip uncertain ones."
  • Drop the framework version extraction step to reduce complexity.

Watch for

  • Generated code in dist/, build/, or generated/ directories being misattributed as primary language signals.
  • Embedded DSLs (SQL in Python strings, GraphQL in TypeScript template literals) inflating language counts.
  • Missing monorepo subdirectories that use a different language than the root.
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.