Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

There is no single scanner that catches every mistake in AI-generated code. Elephant-Goldfish Model (EGM) works before implementation: it helps clarify requirements, turns them into a specification, and uses isolated reviewers to challenge ambiguity and hidden dependencies. CodeQL and Semgrep work after code exists, finding different classes of implementation problems. The most dependable approach is layered: use EGM to reduce design risk, Semgrep for fast pattern feedback, CodeQL for semantic and data-flow vulnerabilities, then require tests and human review.

What is the difference between Elephant-Goldfish and code scanners?

Elephant-Goldfish Model (EGM) is a pre-code specification review process, while CodeQL and Semgrep analyze implemented source code. EGM asks whether the intended behavior is complete and implementable; scanners ask whether the code that was written violates detectable rules or data-flow conditions.

The distinction matters especially with AI coding agents. An agent can faithfully implement an incomplete requirement, choose an unsafe dependency, or miss an edge case that no line of code explicitly contradicts. A scanner can then find insecure flows, banned APIs, bugs, and maintainability issues in the resulting code, but it cannot recover requirements that were never stated.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Tool Lifecycle position Primary signal Best use Important limit
Elephant-Goldfish Model Before implementation Specification ambiguity, missing edge cases, hidden dependencies, implementation readiness Designing and challenging an AI-ready plan Does not prove runtime behavior or absence of security defects
Semgrep IDE, pre-commit, and CI Source-like patterns and customizable rules Fast organization-specific checks and banned patterns Can miss values transformed across files or layers
CodeQL After code is extracted into an analysis database Semantic queries and cross-function data flow Security-sensitive flows and variant analysis Requires supported-language extraction and suitable build context

What does Elephant-Goldfish Model actually do?

EGM is described in its Google repository as “an open-source plugin for Spec-Driven Development with AI coding agents.” It is not an officially supported Google product. The repository uses the Apache 2.0 license.

The model separates deep context from adversarial review. An Elephant session keeps the project context, explores the problem, and drafts a living Markdown specification. Stateless Goldfish subagents then read the draft and relevant source without the earlier conversation’s assumptions. That fresh context is intended to expose unclear language, omitted cases, dependencies, and implementation details that an author may overlook.

How the EGM workflow is organized

  1. Brainstorm: explore the problem, boundaries, constraints, and affected parts of the project with a Goldfish swarm.
  2. Draft: compile the decisions into a living Markdown design document rather than asking an agent to code from a chat transcript.
  3. Review: run comprehension, antagonistic, and implementation-readiness checks. Reviewers test whether they understand the design, attack it for edge cases and hidden dependencies, and verify that it names concrete files, data structures, and function signatures where needed.
  4. Implement: hand the reviewed specification to the coding agent, then validate the implementation with normal engineering controls.

The Google Open Source Blog described the approach in 2026 this way: “The Goldfish Protocol shifts the model from co-design to adversarial validation, using stateless AI instances to probe the design for weaknesses.” That is a description of method, not evidence that EGM detects a fixed share of defects.

Which AI coding mistakes can EGM catch before code exists?

EGM is strongest when a mistake is a gap in intent rather than a syntactic or data-flow violation. A reviewer can challenge the specification before an implementation hides the gap behind plausible code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Ambiguous acceptance criteria: for example, “support large uploads” without defining size limits, timeout behavior, resumability, or user-facing errors.
  • Unexamined edge cases: empty collections, duplicate events, clock skew, partial failures, retries, concurrent updates, or deleted records.
  • Hidden dependencies: an apparently local change that also requires a migration, feature flag, permission update, queue consumer, or cache invalidation.
  • Unclear ownership and boundaries: a specification that does not say which service validates input, which component authorizes an action, or where a new data structure is persisted.
  • Implementation unreadiness: a plan that names an outcome but not the relevant paths, interfaces, schemas, or function contracts an agent needs to make a safe change.

EGM cannot execute the finished program, demonstrate an exploit, prove that authorization is correct, or establish that a requirement is satisfied in production. Those questions require tests, code analysis, runtime checks, and human judgment.

What does Semgrep catch in AI-generated code?

Semgrep matches fast, source-like patterns and lets teams write custom rules. It is useful when you need feedback in an IDE, before a commit, or in CI, and when the rule is naturally expressed as a recognizable code shape.

Good Semgrep targets

  • Organization-specific APIs that must be called with a particular option.
  • Banned functions, insecure defaults, or deprecated libraries.
  • Authentication and logging conventions that can be checked locally.
  • Framework misuse with a known syntax pattern.
  • Simple taint paths within a file, where the relevant source and sink remain visible to the rule.

Custom rules are a major advantage: a team can encode a newly discovered AI habit quickly instead of waiting for a general-purpose rule release. IDE extensions and broad CI-provider support also make Semgrep practical for short feedback loops.

Where Semgrep needs help

A pattern can be context-blind. If a value is renamed, transformed, passed through several modules, or selected through dynamic dispatch, a local match may miss the risk or produce a finding that needs substantial validation. Treat a Semgrep result as a signal to investigate, not as proof that a vulnerability is exploitable or that unreported code is safe. Pair pattern checks with semantic analysis when the risk depends on cross-file data flow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What does CodeQL catch in AI-generated code?

CodeQL extracts a codebase into a database and runs semantic queries over that representation. Queries can follow relationships across functions and files, identify vulnerability patterns, and support variant analysis: once one weakness is found, you can search for similar variants elsewhere.

CodeQL is a strong fit for repositories that need repository-wide context and security-focused data-flow analysis, particularly in GitHub-centered workflows. It can ask questions that are difficult to express as a single text pattern, such as whether user-controlled input can reach a sensitive operation through several calls.

Language and build coverage are prerequisites

GitHub lists CodeQL support for C/C++, C#, Go, Java and Kotlin, JavaScript and TypeScript, Python, Ruby, Rust, Swift, and GitHub Actions workflows. An unsupported language, incomplete extraction, or an unsuitable build configuration can produce incomplete analysis or no alerts. Confirm that every security-relevant component is covered before treating a clean result as meaningful.

The operational trade-off

Deep semantic analysis generally needs language extraction and, for some ecosystems, a representative build. That setup and database analysis can take more time and operational work than source-pattern matching. The payoff is stronger cross-function reasoning and reusable queries, not a guarantee of complete detection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Is Elephant-Goldfish a replacement for CodeQL or Semgrep?

No. EGM and the scanners operate at different lifecycle points and answer different questions. EGM should be treated as a design-risk control that precedes implementation; it does not substitute for code analysis, tests, or human approval.

Question you need answered Most relevant control
Did we define the behavior, boundaries, and failure cases clearly? EGM brainstorming and specification review
Did the code use a banned API or violate a local convention? Semgrep custom or built-in pattern rules
Can untrusted data reach a sensitive operation through multiple calls? CodeQL semantic and data-flow queries
Does the system behave correctly under real scenarios? Automated tests, runtime checks, and human review

How should you choose among the three tools?

Choose based on lifecycle position, detection depth, feedback location, coverage, customization, and governance rather than on a single “accuracy” ranking. No authoritative source establishes a universal detection percentage for these tools, and their results depend on the code, rules, languages, configuration, and review process.

Choose EGM when the risk is still in the plan

Use EGM when an AI agent is about to make a cross-cutting change, when requirements are evolving, or when failures would be expensive to discover after implementation. It is especially useful for migrations, new workflows, permission-sensitive features, and changes spanning multiple services.

Choose Semgrep for fast, local, customizable feedback

Use Semgrep when developers need a result in the IDE or pre-commit hook, when rules are mostly syntactic, or when your organization has conventions that generic analyzers do not know. Keep a path for triaging false positives and add semantic analysis for risks that cross module boundaries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose CodeQL for repository-wide semantic security analysis

Use CodeQL when supported-language extraction is reliable and you need cross-function data flow, vulnerability queries, or variant analysis. Budget for database generation, build configuration, query maintenance, and coverage checks.

What layered workflow works best for AI-generated changes?

A layered pipeline catches different failure classes without pretending that one clean report proves correctness.

  1. Clarify the requirement with EGM. Record scope, exclusions, acceptance criteria, failure behavior, dependencies, data changes, authorization boundaries, and affected paths in a self-contained specification.
  2. Run comprehension and adversarial reviews. Ask fresh reviewers to restate the design, look for edge cases and hidden dependencies, and reject it if the implementation details are not actionable.
  3. Implement from the reviewed specification. Give the coding agent the approved document and constrain the change to the stated boundaries. Keep generated edits reviewable and small enough to test.
  4. Run Semgrep early. Use IDE or pre-commit checks for banned patterns, local conventions, and organization-specific APIs so cheap failures are fixed before CI.
  5. Run CodeQL where coverage is valid. Confirm that every relevant language and build path was extracted, then inspect data-flow findings and search for variants of confirmed defects.
  6. Execute tests and conduct human review. Include unit, integration, authorization, negative, and regression tests appropriate to the change. Have a reviewer verify the requirement against behavior, not merely against scanner status.

What are the common failure modes when scanning AI-written code?

  • Assuming a clean report means “safe”: a scanner only reports issues its configured rules can detect in covered files and languages.
  • Scanning too late: implementation analysis may reveal that the original requirement was underspecified, forcing an expensive redesign.
  • Ignoring coverage gaps: unsupported languages, generated files, excluded paths, and failed builds can leave important code unanalyzed.
  • Over-trusting patterns: a match may be harmless in context, while a transformed or cross-service flow may evade a local rule.
  • Using one quality gate for every risk: maintainability thresholds do not validate business invariants or threat models.
  • Letting AI close its own findings: the same agent that introduced a defect may rationalize a weak fix. Require an independent review and tests.

How to recover from a misleading result

  1. Check the analyzer log for skipped files, extraction errors, unsupported languages, and excluded directories.
  2. Reduce the finding to a minimal code path and determine whether it is a true positive, false positive, or coverage artifact.
  3. For a true positive, add a regression test and, where useful, a custom Semgrep rule or CodeQL query so the defect class stays visible.
  4. For a false positive, document the safe invariant and narrow the rule or suppression to the smallest justified scope.
  5. If the issue is a missing requirement, update the EGM specification and acceptance criteria instead of only patching the current implementation.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What should a team measure?

Do not publish or rely on a single detection percentage. Measure whether the process improves outcomes: time from AI-generated change to useful feedback, proportion of changed code covered by each analyzer, recurring finding categories, false-positive rate, escaped defects, test additions, and time spent triaging findings.

Track coverage separately for EGM-reviewed designs, Semgrep rules, CodeQL-extracted languages, and tests. A rising alert count can mean better detection, worse generated code, or noisier rules; interpret it alongside confirmed defects and developer resolution time.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the practical verdict for a small team?

Start with the control that matches your largest current risk. If AI agents routinely misunderstand requirements, add an EGM-style specification and adversarial review before investing in more scanner rules. If the requirements are stable but generated code repeats unsafe patterns, add Semgrep in the IDE and pre-commit path. Add CodeQL when cross-function security flows matter and the repository can be extracted reliably.

For mature teams, the controls are complementary rather than mutually exclusive: EGM reduces design ambiguity, Semgrep shortens feedback loops, and CodeQL deepens semantic security analysis. Tests and accountable human review remain necessary after all three report clean results.

Frequently Asked Questions

Can an AI coding agent run Elephant-Goldfish and a scanner in the same pull request?

Yes. Run the specification and adversarial checks before the agent edits code, then attach Semgrep and CodeQL results to the implementation pull request as applicable. Keep the specification review and code review as separate approvals so a passing scanner does not silently waive an unresolved design concern.

How do I know whether a CodeQL clean result is meaningful?

Verify that every relevant language was supported, the extraction completed without errors, and generated or vendored paths were handled intentionally. Also confirm that the query suites match your threat model; an unconfigured query is not evidence that the corresponding defect class is absent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I write custom Semgrep rules for every AI mistake?

Write a rule when the mistake has a stable, recognizable code shape and the rule can provide timely feedback. For defects that depend on values moving across functions or services, preserve a regression test and use semantic analysis instead of forcing a brittle pattern.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.