Skip to content

GitHub Copilot Blocking Responses Matching Public Code

When using GitHub Copilot in VS Code, developers occasionally encounter the following error:

WARNING

Sorry, the response matched public code so it was blocked. Please rephrase your prompt

This occurs when Copilot identifies that a generated code suggestion matches existing public repositories on GitHub. Here's what you need to know about this behavior and how to resolve it.

Why Code Gets Blocked

GitHub Copilot automatically checks suggestions against a database of publicly available code. This happens when:

  1. Your prompt would generate output closely matching existing public code (150+ characters including surrounding context)
  2. Copilot detects a near-identical match to code on GitHub
  3. Your account has the "block public code matches" setting enabled

The system is designed to help avoid potential licensing issues, particularly for organizations concerned about code provenance.

Solutions to Bypass the Block

Modify your prompt to make it more specific and contextually unique:

markdown
BAD: "Create login function"
GOOD: "Create login handler for Express API using JWT with 30min expiration"
  • Why it works: Narrower context reduces the chance of matching generic public code.
  • Effectiveness: Most instances are resolved with moderate prompt adjustments.

2. Modify Copilot's Security Settings (Individual Accounts Only)

For personal GitHub accounts:

  1. Go to GitHub Settings > Copilot
  2. Under "Suggestions matching public code":
  3. Select Allow from the dropdown menu
  4. Click Save

Organizational Limitations

Enterprise-managed Copilot subscriptions often enforce mandatory blocking. If you don't see the dropdown option or can't save changes, your organization's policy overrides individual settings. Contact your administrator for exceptions.

Key Considerations

  • Licensing Implications: Allowing matched public code doesn't guarantee license compliance. Always review generated code.
  • False Positives: Generic algorithms/common patterns are frequently blocked. More specific prompts reduce false blocks.
  • Performance Tradeoff: "Allow" mode may appear faster since suggestions aren't filtered post-generation.

Copilot's code matching system reflects GitHub's commitment to responsible AI practices. For most users, prompt refinement provides the best balance between convenience and compliance. Work account holders experiencing persistent blocks should consult their organization's Copilot policy administrators.

TIP

For documentation updates, refer to GitHub's official Public Code Matching Policy.