Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save drewdomi/9cf1f36a13d38b7072b7ab8718ff76ac to your computer and use it in GitHub Desktop.

Select an option

Save drewdomi/9cf1f36a13d38b7072b7ab8718ff76ac to your computer and use it in GitHub Desktop.

Documentation: Gemini Custom Instructions Optimization

1. Implementation Order

To ensure the logic flows correctly, paste the parts in this sequence into your Gemini settings boxes. Since most interfaces provide two boxes, follow this combination:

  • Box 1 (Context/About You): Paste Part 1.
  • Box 2 (How to Respond): Paste Part 2 immediately followed by Part 3 (ensure no extra spaces are added between them).
    • Note: If Box 2 rejects the combined text, it means the combined encoded length is over 1,500. In that case, move the end of Part 2 into Box 1.

2. Technical Post-Mortem: What went wrong?

You encountered Error 164 during the batchexecute POST call. Here is the technical breakdown of why the original and early splits failed:

A. The "Encoding Bloat" (Escaping)

The Gemini settings interface has a visible limit of 1,500 characters. However, when you click "Save," your browser sends this text as a JSON string. In JSON, specific characters must be "escaped" with a backslash (\).

  • " (Double Quote) becomes \" (2 chars)
  • / (Forward Slash) becomes \/ (2 chars)
  • (New line) becomes \n (2 chars)
  • Backticks and special symbols often expand similarly.

Result: A block of text that looks like 1,400 characters to you might actually be 1,700+ characters to the server, causing the 164 error.

B. Payload Overflow

The di (data input) value in your error log showed large numbers (e.g., 3004). This indicates the total packet size was exceeding the buffer limits allowed for the "Personalized Intelligence" metadata fields.


3. Rules for Future Optimization

If you need to update these instructions or create new ones, follow these "Safe Compression" rules:

  1. The 1,000-Character Safety Rule: Never aim for exactly 1,500 characters. Aim for 1,000 to 1,100 visible characters per part to leave "headroom" for JSON encoding.
  2. Symbol Economy: Avoid unnecessary double quotes (") or backslashes (\). Use single quotes (') where possible, as they often require less escaping in specific web protocols.
  3. No Newlines: Each newline (Enter) is encoded as \n. In a long list, removing 20 enters saves 40 encoded characters.
  4. Concatenation Logic: Always split at the end of a logical section (e.g., after a . or *) to ensure the AI doesn't lose context mid-sentence if a part fails to save.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment