abhigyanpatwari/GitNexus · info · Error

No JSON found in response

Error message

No JSON found in response

What it means

Thrown inside parseEnrichmentResponse when the LLM's response string contains no substring matching /\{[\s\S]*\}/ (i.e. no brace-delimited JSON object). IMPORTANT: this throw is fully internal — parseEnrichmentResponse wraps its parsing logic in try/catch and falls back to {name: fallbackLabel, keywords: [], description: ''} on any failure, including this one. A caller of enrichClusters never observes it; it degrades silently to the heuristic label.

Source

Thrown at gitnexus/src/core/ingestion/cluster-enricher.ts:65

  return `Analyze this code cluster and provide a semantic name and short description.

Heuristic: "${heuristicLabel}"
Members: ${memberList}${members.length > 20 ? ` (+${members.length - 20} more)` : ''}

Reply with JSON only:
{"name": "2-4 word semantic name", "description": "One sentence describing purpose"}`;
};

// ============================================================================
// PARSE LLM RESPONSE
// ============================================================================

const parseEnrichmentResponse = (response: string, fallbackLabel: string): ClusterEnrichment => {
  try {
    // Extract JSON from response (handles markdown code blocks)
    const jsonMatch = response.match(/\{[\s\S]*\}/);
    if (!jsonMatch) {
      throw new Error('No JSON found in response');
    }

    const parsed = JSON.parse(jsonMatch[0]);

    return {
      name: parsed.name || fallbackLabel,
      keywords: Array.isArray(parsed.keywords) ? parsed.keywords : [],
      description: parsed.description || '',
    };
  } catch {
    // Fallback if parsing fails
    return {
      name: fallbackLabel,
      keywords: [],
      description: '',
    };
  }
};

View on GitHub (pinned to d540b00184)

Solutions

  1. This error is already handled — no caller action is required; the cluster simply keeps its heuristic label.
  2. If enrichment quality is poor across many clusters, inspect the raw LLM responses (add logging around llmClient.generate) to see why JSON is missing.
  3. Tune the prompt or switch models if the LLM consistently returns non-JSON.
  4. Verify the LLMClient.generate implementation returns the model's text content, not a wrapper object/stringified HTTP response.

Example fix

// before — mock LLMClient returns prose, triggering the (caught) fallback
const client = { generate: async () => 'Sorry, I cannot help.' };

// after — returns the expected JSON shape
const client = { generate: async () => '{"name":"Auth Module","description":"Handles user authentication"}' };
Defensive patterns

Strategy: fallback

Validate before calling

// The error is already caught internally and falls back to the heuristic label.
// To validate LLM output shape before relying on enrichment fields:
function looksLikeJsonEnvelope(response: string): boolean {
  return /\{[\s\S]*\}/.test(response);
}
if (!looksLikeJsonEnvelope(await llmClient.generate(prompt))) {
  logger.warn('LLM returned no JSON envelope — enrichment will fall back');
}

Type guard

function isEnrichmentJson(v: unknown): v is { name?: string; description?: string; keywords?: unknown[] } {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Try / catch

// enrichClusters already handles this internally; callers need no try/catch.
// If you call parseEnrichmentResponse directly, mirror its catch:
let enrichment;
try { enrichment = parseEnrichmentResponse(raw, fallbackLabel); }
catch { enrichment = { name: fallbackLabel, keywords: [], description: '' }; }

Prevention

When it happens

Trigger: The LLM returns plain prose with no JSON object at all (e.g. 'I cannot help with that.'), an empty string, or a response containing only an array (no '{'). Because the regex requires an opening brace, a bare array or scalar text triggers it.

Common situations: LLM refused/declined the prompt and returned prose; LLM hit a content filter returning no JSON; truncated response cut off before the JSON; wrong model endpoint returning a status page or error text instead of a completion.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@d540b00184 (2026-08-12). Data as JSON: /api/errors/7486949abb675984. Report an issue: GitHub.